-
Notifications
You must be signed in to change notification settings - Fork 55
/
quickbooks.cfc
119 lines (111 loc) · 3.83 KB
/
quickbooks.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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="revokeTokenEndpoint" type="string";
property name="redirect_uri" type="string";
/**
* I return an initialized quickbooks 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.
* @revokeTokenEndpoint The URL endpoint that handles revoking token.
* @redirect_uri The URL to redirect the user back to following authentication.
**/
public quickbooks function init(
required string client_id,
required string client_secret,
required string authEndpoint = 'https://appcenter.intuit.com/connect/oauth2/',
required string accessTokenEndpoint = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer/',
required string revokeTokenEndpoint = 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke',
required string redirect_uri
)
{
setRevokeTokenEndpoint(arguments.revokeTokenEndpoint);
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.
* @state A unique string value of your choice that is hard to guess. Used to prevent CSRF.
**/
public string function buildRedirectToAuthURL(
array scope = [],
string state
){
var sParams = {
'response_type' = 'code'
};
if( arrayLen( arguments.scope ) ){
structInsert( sParams, 'scope', arrayToList( arguments.scope, ' ' ) );
}
if( len( arguments.state ) ){
structInsert( sParams, 'state', arguments.state );
}
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
);
}
/**
* I make the HTTP request to refresh the access token.
* @refresh_token The refresh_token to grant a new access token.
**/
public struct function refreshAccessTokenRequest(
required string refresh_token
){
var aFormFields = [
{
'name' = 'grant_type',
'value' = 'refresh_token'
}
];
return super.refreshAccessTokenRequest(
refresh_token = arguments.refresh_token,
formfields = aFormFields
);
}
/**
* I make the HTTP request to revoke a token.
* @refresh_token The refresh_token to revoke.
**/
public struct function revokeTokenRequest(
required string refresh_token
){
var stuResponse = {};
var httpService = new http();
httpService.setMethod( "post" );
httpService.setCharset( "utf-8" );
httpService.setUrl( getRevokeTokenEndpoint() );
httpService.addParam( type="header", name="Authorization", value="Basic " & ToBase64(getClient_id() & ":" & getClient_secret()));
httpService.addParam( type="formfield", name="token", value=arguments.refresh_token );
var result = httpService.send().getPrefix();
if( '200' == result.ResponseHeader[ 'Status_Code' ] ) {
stuResponse.success = true;
stuResponse.content = result.FileContent;
} else {
stuResponse.success = false;
stuResponse.content = result.Statuscode;
}
return stuResponse;
}
}