-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathgithub.cfc
70 lines (64 loc) · 3.01 KB
/
github.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
component extends="oauth2" accessors="true" {
property name="client_id" type="string";
property name="client_secret" type="string";
property name="authEndpoint" type="string";
property name="accessTokenEndpoint" type="string";
property name="redirect_uri" type="string";
/**
* I return an initialized github object instance.
* @client_id The client ID for your application.
* @client_secret The client secret for your application.
* @authEndpoint The URL endpoint that handles the authorisation.
* @accessTokenEndpoint The URL endpoint that handles retrieving the access token.
* @redirect_uri The URL to redirect the user back to following authentication.
**/
public github function init(
required string client_id,
required string client_secret,
required string authEndpoint = 'http://github.com/login/oauth/authorize',
required string accessTokenEndpoint = 'https://github.com/login/oauth/access_token',
required string redirect_uri
)
{
super.init(
client_id = arguments.client_id,
client_secret = arguments.client_secret,
authEndpoint = arguments.authEndpoint,
accessTokenEndpoint = arguments.accessTokenEndpoint,
redirect_uri = arguments.redirect_uri
);
return this;
}
/**
* I return the URL as a string which we use to redirect the user for authentication.
* @scope An optional array of values to pass through for scope access. If not provided, scope defaults to an empty list for users that have not authorized any scopes for the application. For users who have authorized scopes for the application, the user won't be shown the OAuth authorization page with the list of scopes. Instead, this step of the flow will automatically complete with the set of scopes the user has authorized for the application. For example, if a user has already performed the web flow twice and has authorized one token with user scope and another token with repo scope, a third web flow that does not provide a scope will receive a token with user and repo scope.
* @state A unique string value of your choice that is hard to guess. Used to prevent CSRF.
* @allow_signup Whether or not unauthenticated users will be offered an option to sign up for GitHub during the OAuth flow. The default is true. Use false in the case that a policy prohibits signups.
Set the parameter value to an email address or sub identifier.
**/
public string function buildRedirectToAuthURL(
required array scope,
required string state,
boolean allow_signup = true
){
var sParams = {
'scope' = arrayToList( arguments.scope, ' ' ),
'state' = arguments.state,
'allow_signup' = arguments.allow_signup
};
return super.buildRedirectToAuthURL( sParams );
}
/**
* I make the HTTP request to obtain the access token.
* @code The code returned from the authentication request.
**/
public struct function makeAccessTokenRequest(
required string code
){
var aFormFields = [];
return super.makeAccessTokenRequest(
code = arguments.code,
formfields = aFormFields
);
}
}