badgateway / oauth2-client

OAuth2 client for Node and browsers
https://www.npmjs.com/package/@badgateway/oauth2-client
MIT License
269 stars 31 forks source link

Add support for token revocation #126

Closed adambom closed 7 months ago

adambom commented 10 months ago

This PR adds support for token revocation. It's implemented similarly to how token introspection is implemented. Let me know what you think. Happy to write tests too just let me know how you'd like them structured and where. I didn't see an obvious place for the tests to live.

Usage:

const client = new OAuth2Client({
  // ...

  // Can also be auto-discovered if discoveryEndpoint is supplied
  revocationEndpoint: '/revoke'
});

const token = await client.clientCredentials();

await client.revoke(token);

// can also supply tokenTypeHint (default is 'access_token')
await client.revoke(token, 'access_token');

// To revoke a refresh token
await client.revoke(token, 'refresh_token');

Fixes #125

adambom commented 10 months ago

There are currently unittests in the test/ directory. Running 'npm test' should execute them. If you're not comfortable adding these I'll find some time writing them

More specifically, I was looking for tests that invoke client.introspect so I could copy them, but I couldn't find any. Am I missing something?

evert commented 10 months ago

There are currently unittests in the test/ directory. Running 'npm test' should execute them. If you're not comfortable adding these I'll find some time writing them

More specifically, I was looking for tests that invoke client.introspect so I could copy them, but I couldn't find any. Am I missing something?

No, this library doesn't have a 100% coverage , but I've been trying to add them with every change or new feature

adambom commented 10 months ago

There are currently unittests in the test/ directory. Running 'npm test' should execute them. If you're not comfortable adding these I'll find some time writing them

More specifically, I was looking for tests that invoke client.introspect so I could copy them, but I couldn't find any. Am I missing something?

No, this library doesn't have a 100% coverage , but I've been trying to add them with every change or new feature

I'll see what I can do

adambom commented 10 months ago

Ok, have a look, let me know what you think

evert commented 9 months ago

Geez my last 2 comments were in 'draft' for a month and a half , sorry . Forgot to hit the green button