Constructor
new OAuth(attributes, header)
Parameters:
Name | Type | Description |
---|---|---|
attributes |
Object | Initial set of attribute/value pairs with which to seed this OAuth object |
header |
string | Actual name for the Authorization header (default 'Authorization') |
- Source:
Examples
Initialize OAuth with client credentials
var myOAuth = new oj.OAuth('X-Authorization', {...Client Credentials ...});
Initialize OAuth with access_token
var myOAuth = new oj.OAuth('X-Authorization', {...Access Token...});
Initialize empty OAuth and set access_token
var myOAuth = new oj.OAuth();
myOAuth.setAccessTokenResponse({...Access Token...});
Methods
-
cleanAccessTokenRequest()
-
Clean request part of the OAuth object (client credentials, uri endpoint) Null and remove all data from request part of the OAuth object
- Source:
-
cleanAccessTokenResponse()
-
Clean response part of the OAuth object (access_token, e.t.c.) Null and remove all data from response part of the OAuth object
- Source:
-
clientCredentialGrant()
-
Request for access_token(bearer token) using Client Credential Authorization Grant. Initialize response part of the OAuth object (access_token, e.t.c.)
- Source:
Example
Set/Re-set response part of the OAuth object using Client Credentials
myOAuth.clientCredentialGrant();
-
getAccessTokenRequest() → {Object}
-
Get request part of the OAuth object (client credentials, uri endpoint)
- Source:
Returns:
cached request- Type
- Object
-
getAccessTokenResponse() → {Object}
-
Get response part of the OAuth object (access_token, e.t.c.)
- Source:
Returns:
cached response- Type
- Object
-
getHeader() → {Object}
-
Calculates Authorization header based on client credentials or access_token
- Source:
Returns:
OAuth 2.0 Authorization header- Type
- Object
Example
Get Authorization header
myOAuth.getHeader();
-
isInitialized() → {boolean}
-
Check is OAuth initialized (not null access_token).
- Source:
Returns:
true/false- Type
- boolean
Example
Check if OAuth initialized
if(myOAuth.isInitialized()) console.log('Initialized');
-
setAccessTokenRequest(data)
-
Set request part of the OAuth object (client credentials, uri endpoint)
Parameters:
Name Type Description data
Object current client credentials and uri - Source:
Example
'Initialize' request part of the OAuth object with client credentials and calculate access_token
myOAuth.setAccessTokenRequest({...Client Credentials ...}); myOAuth.clientCredentialGrant();
-
setAccessTokenResponse(data)
-
Set response part of the OAuth object (access_token, e.t.c.)
Parameters:
Name Type Description data
Object current response - Source:
Example
'Initialize' response part of the OAuth object with access_token
myOAuth.setAccessTokenResponse({...Access Token...});