This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
getAccessToken
Alex Vernacchia edited this page Mar 16, 2015
·
2 revisions
When using a version >= v1.0.0 you have access to the promise implementation. The examples for both callbacks and promises are below.
-
getAccessToken( options [, callback ])
-
options
- required: no
- Type:
Object
- Extra options used on token request. See [request modules options][3]
-
options.force
- required: no
- Type:
Boolean
- default:
false
- If true, token will always be requested from API regardless of expiration
-
callback( error, data )
- required: no (required pre v1.0.0)
- Type:
Function
- Function that will be executed after token request completes
-
parameters
- error - error encountered.
null
if no error - data - object with data and response
- accessToken ( data.accessToken ) - access token
- expiresIn ( data.expiresIn ) - time until token expiration
- error - error encountered.
-
####Callbacks
var options = {
// whatever request options you want
// See https://github.com/mikeal/request#requestoptions-callback
force: true // I want to force a request
};
FuelAuthClient.getAccessToken(options, function(err, data) {
if(err) {
console.log(err);
return;
}
// data.accessToken = your token
// data.expiresIn = how long until token expiration
console.log(data);
});
// OR don't pass any options
FuelAuthClient.getAccessToken(function(err, data) {
if(err) {
console.log(err);
return;
}
// data.accessToken = your token
// data.expiresIn = how long until token expiration
console.log(data);
});
####Promises
FuelAuthClient.getAccessToken(options)
.then(function(data) {
// data.accessToken = your token
// data.expiresIn = how long until token expiration
console.log(data);
})
.catch(function(err) {
console.log(err);
});
// OR don't pass any options
FuelAuthClient.getAccessToken()
.then(function(data) {
// data.accessToken = your token
// data.expiresIn = how long until token expiration
console.log(data);
})
.catch(function(err) {
console.log(err);
});