-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for sending client_secret with authorization_code
Also added a bunch of tests for this. Fixes #70
- Loading branch information
Showing
7 changed files
with
124 additions
and
14 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
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,75 @@ | ||
import { testServer } from './test-server'; | ||
import { OAuth2Client } from '../src'; | ||
import { expect } from 'chai'; | ||
|
||
describe('authorization-code', () => { | ||
|
||
it('should send requests to the token endpoint', async() => { | ||
|
||
const server = testServer(); | ||
|
||
const client = new OAuth2Client({ | ||
server: server.url, | ||
tokenEndpoint: '/token', | ||
clientId: 'test-client-id', | ||
}); | ||
|
||
const result = await client.authorizationCode.getToken({ | ||
code: 'code_000', | ||
redirectUri: 'http://example/redirect', | ||
}); | ||
|
||
expect(result.accessToken).to.equal('access_token_000'); | ||
expect(result.refreshToken).to.equal('refresh_token_000'); | ||
expect(result.expiresAt).to.be.lessThanOrEqual(Date.now() + 3600_000); | ||
expect(result.expiresAt).to.be.greaterThanOrEqual(Date.now() + 3500_000); | ||
|
||
server.close(); | ||
|
||
const request = server.lastRequest(); | ||
expect(request.headers.get('Authorization')).to.equal(null); | ||
|
||
expect(request.body).to.eql({ | ||
client_id: 'test-client-id', | ||
grant_type: 'authorization_code', | ||
code: 'code_000', | ||
redirect_uri: 'http://example/redirect', | ||
}); | ||
|
||
}); | ||
|
||
it('should send client_id and client_secret in the Authorization header if secret was specified', async() => { | ||
|
||
const server = testServer(); | ||
|
||
const client = new OAuth2Client({ | ||
server: server.url, | ||
tokenEndpoint: '/token', | ||
clientId: 'test-client-id', | ||
clientSecret: 'test-client-secret', | ||
}); | ||
|
||
const result = await client.authorizationCode.getToken({ | ||
code: 'code_000', | ||
redirectUri: 'http://example/redirect', | ||
}); | ||
|
||
expect(result.accessToken).to.equal('access_token_000'); | ||
expect(result.refreshToken).to.equal('refresh_token_000'); | ||
expect(result.expiresAt).to.be.lessThanOrEqual(Date.now() + 3600_000); | ||
expect(result.expiresAt).to.be.greaterThanOrEqual(Date.now() + 3500_000); | ||
|
||
server.close(); | ||
|
||
const request = server.lastRequest(); | ||
expect(request.headers.get('Authorization')).to.equal('Basic ' + btoa('test-client-id:test-client-secret')); | ||
|
||
expect(request.body).to.eql({ | ||
grant_type: 'authorization_code', | ||
code: 'code_000', | ||
redirect_uri: 'http://example/redirect', | ||
}); | ||
|
||
}); | ||
|
||
}); |
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