forked from auth0/node-auth0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding getAccessToken method to api.
- Loading branch information
Showing
6 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"strict": false, | ||
"smarttabs": true, | ||
"expr": true, | ||
|
||
|
||
"evil": true, | ||
"browser": true, | ||
"regexdash": true, | ||
"wsh": true, | ||
"trailing": true, | ||
"sub": true, | ||
"unused": true, | ||
"laxcomma": true, | ||
|
||
"globals": { | ||
"after": false, | ||
"before": false, | ||
"afterEach": false, | ||
"beforeEach": false, | ||
"describe": false, | ||
"it": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
var expect = require('chai').expect; | ||
|
||
var nock = require('nock'); | ||
var querystring = require('querystring'); | ||
|
||
var Auth0 = require('../lib'); | ||
|
||
|
||
describe('API', function () { | ||
|
||
describe('getAccessToken', function () { | ||
it('should work on request success', function (done) { | ||
var scope; | ||
|
||
var domain = 'mydomain.auth0.com', | ||
clientID = 'SOME_SECRET_ID', | ||
clientSecret = 'SOME_SECRET_SHHHH', | ||
accessToken = 'OMG_SO_TOKEN_SUCH_CRYPTO'; | ||
|
||
var qs = querystring.stringify({ | ||
client_id: clientID, | ||
client_secret: clientSecret, | ||
grant_type: 'client_credentials' | ||
}); | ||
|
||
scope = nock('https://' + domain) | ||
.post('/oauth/token', qs) | ||
.reply(200, { | ||
'access_token': accessToken, | ||
'token_type': 'bearer' | ||
}); | ||
|
||
var api = new Auth0({ | ||
domain: domain, | ||
clientID: clientID, | ||
clientSecret: clientSecret | ||
}); | ||
|
||
api.getAccessToken(function (err, token) { | ||
expect(err).to.not.exist; | ||
expect(token).to.be.equal(accessToken); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should fail when request fails', function (done) { | ||
var scope; | ||
|
||
var error = 'Error: Token could not be retrieved'; | ||
|
||
var domain = 'mydomain.auth0.com', | ||
clientID = 'SOME_SECRET_ID', | ||
clientSecret = 'SOME_SECRET_SHHHH'; | ||
|
||
var qs = querystring.stringify({ | ||
client_id: clientID, | ||
client_secret: clientSecret, | ||
grant_type: 'client_credentials' | ||
}); | ||
|
||
scope = nock('https://' + domain) | ||
.post('/oauth/token', qs) | ||
.reply(401, error); | ||
|
||
var api = new Auth0({ | ||
domain: domain, | ||
clientID: clientID, | ||
clientSecret: clientSecret | ||
}); | ||
|
||
api.getAccessToken(function (err, token) { | ||
expect(err).not.to.be.equal(null); | ||
expect(err.name).to.be.equal('ApiError'); | ||
expect(err.statusCode).to.be.equal(401); | ||
expect(token).to.not.exist; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.