-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from adambom/adambom-revoke
Add support for token revocation
- Loading branch information
Showing
6 changed files
with
156 additions
and
16 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,68 @@ | ||
import { testServer } from './test-server'; | ||
import { OAuth2Client } from '../src'; | ||
import { expect } from 'chai'; | ||
|
||
describe('Token revocation', () => { | ||
const server = testServer(); | ||
describe('should revoke access token when requested', async () => { | ||
|
||
const client = new OAuth2Client({ | ||
server: server.url, | ||
tokenEndpoint: '/token', | ||
revocationEndpoint: '/revoke', | ||
clientId: 'test-client-id', | ||
clientSecret: 'test-client-secret', | ||
}); | ||
|
||
const token = await client.clientCredentials(); | ||
|
||
describe('When token type hint is not specified', () => { | ||
it('should assume token type is access token', async () => { | ||
await client.revoke(token); | ||
|
||
const request = server.lastRequest(); | ||
expect(request.body).to.eql({ | ||
token: token.accessToken, | ||
token_type_hint: 'access_token', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('When token type is specified as access token', () => { | ||
it('should supply access token', async () => { | ||
await client.revoke(token, 'access_token'); | ||
|
||
const request = server.lastRequest(); | ||
expect(request.body).to.eql({ | ||
token: token.accessToken, | ||
token_type_hint: 'access_token', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('When token type is specified as refresh token', () => { | ||
it('should supply access token', async () => { | ||
await client.revoke(token, 'refresh_token'); | ||
|
||
const request = server.lastRequest(); | ||
expect(request.body).to.eql({ | ||
token: token.refreshToken, | ||
token_type_hint: 'refresh_token', | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Discovery', () => { | ||
const client = new OAuth2Client({ | ||
server: server.url, | ||
discoveryEndpoint: '/discover', | ||
clientId: 'test-client-id', | ||
}); | ||
|
||
it('Should discover revocation endpoint', async () => { | ||
const result = await client.getEndpoint('revocationEndpoint'); | ||
expect(result).to.equal(server.url + '/revoke'); | ||
}); | ||
}); | ||
}); |
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