forked from lelylan/simple-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to Authorization Code flow and to basic Access Token fu…
…nctionalities
- Loading branch information
1 parent
5bb9ae6
commit 8302489
Showing
12 changed files
with
141 additions
and
82 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
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,29 @@ | ||
// | ||
// Access Token class | ||
// | ||
module.exports = function(config) { | ||
|
||
var core = require('./../core')(config); | ||
require('date-utils'); | ||
|
||
// Returns the OAuth2.AccessToken instance. | ||
// | ||
// * `token` - An object containing the token object returned from the OAuth2 server. | ||
// maintain state between the request and the callback. | ||
// | ||
function create(token) { | ||
this.token = token; | ||
this.token.expires_at = (new Date).addSeconds(7200); | ||
return this | ||
} | ||
|
||
function expired() { | ||
return (Date.compare(this.token.expires_at, new Date) == -1) ? false : true | ||
} | ||
|
||
return { | ||
'create' : create, | ||
'token': this.token, | ||
'expired': expired | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
'authorizationPath' : '/oauth/authorization', | ||
'tokenPath' : '/oauth/token', | ||
'client': {} | ||
'client': {}, | ||
} |
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,57 @@ | ||
var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://example.org' } }, | ||
OAuth2 = require('./../lib/simple-oauth2.js')(credentials), | ||
qs = require('querystring'), | ||
nock = require('nock'); | ||
|
||
var request, result, token, error; | ||
|
||
|
||
describe.only('OAuth2.AccessToken',function() { | ||
|
||
beforeEach(function(done) { | ||
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code' }; | ||
request = nock('https://example.org:443').post('/oauth/token', params).replyWithFile(200, __dirname + '/fixtures/access_token.json'); | ||
done(); | ||
}) | ||
|
||
beforeEach(function(done) { | ||
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com' } | ||
OAuth2.AuthCode.getToken(params, function(e, r) { | ||
error = e; result = r; done(); | ||
}) | ||
}) | ||
|
||
beforeEach(function(done) { | ||
token = OAuth2.AccessToken.create(result); | ||
done(); | ||
}); | ||
|
||
describe('#create',function() { | ||
it('creates an access token',function() { | ||
token.should.have.property('token'); | ||
}); | ||
}); | ||
|
||
|
||
describe('#expired',function() { | ||
|
||
describe('when not expired', function() { | ||
|
||
it('returns false',function() { | ||
token.expired().should.be.true | ||
}); | ||
}); | ||
|
||
describe('when expired', function() { | ||
|
||
beforeEach(function(done) { | ||
token.token.expires_at = Date.yesterday(); | ||
done(); | ||
}); | ||
|
||
it('returns false',function() { | ||
token.expired().should.be.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"access_token": "4adc339e06c20e84c41d0c04c8ad5daf89cc3655d79b399930d112f5f7fXXXXX", | ||
"refresh_token": "ec1a59d298aa51b3f133b6135b817bb19eb917aac5bc7821d410ffbf5ebXXXXX", | ||
"token_type": "bearer", | ||
"expires_in": 7200 | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.