forked from lelylan/simple-oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth-code.js
47 lines (37 loc) · 1.58 KB
/
auth-code.js
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
var credentials = { clientID: 'client-id', clientSecret: 'client-secret', site: 'https://example.org' },
OAuth2 = require('./../lib/simple-oauth2.js')(credentials),
qs = require('querystring'),
nock = require('nock');
var request, result, error;
describe('OAuth2.AuthCode',function() {
describe('#authorizeURL', function(){
beforeEach(function(done) {
var params = { 'redirect_uri': 'http://localhost:3000/callback', 'scope': 'user', 'state': '02afe928b' };
result = OAuth2.AuthCode.authorizeURL(params);
done();
})
it('returns the authorization URI', function() {
var expected = 'https://example.org/oauth/authorize?redirect_uri=' + encodeURIComponent('http://localhost:3000/callback') + '&scope=user&state=02afe928b&response_type=code&client_id=client-id';
result.should.eql(expected);
})
});
describe('#getToken',function() {
beforeEach(function(done) {
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code', 'client_id': 'client-id', 'client_secret': 'client-secret' };
request = nock('https://example.org').post('/oauth/token', qs.stringify(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();
})
})
it('makes the HTTP request', function() {
request.isDone();
});
it('returns an access token',function() {
result.should.have.property('access_token');
});
});
});