Skip to content

Commit

Permalink
Add support for revoking a refresh token (#91)
Browse files Browse the repository at this point in the history
According to [RFC 7009, Section
2.1](https://datatracker.ietf.org/doc/html/rfc7009#section-2.1), the
`token_type_hint` parameter for token revocation requests is optional.
Therefore, we only set the `token_type_hint` when the options.tokenType
is specified.
  • Loading branch information
ponko2 authored May 29, 2024
1 parent ba9fb2b commit 08b1d26
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,21 @@ export class OAuth2Strategy<
}

public revokeToken(
accessToken: string,
options: { signal?: AbortSignal } = {},
token: string,
options: {
signal?: AbortSignal;
tokenType?: "access_token" | "refresh_token";
} = {},
) {
if (this.options.tokenRevocationEndpoint === undefined) {
throw new Error("Token revocation endpoint is not set");
}

let context = new TokenRevocationRequestContext(accessToken);
let context = new TokenRevocationRequestContext(token);

context.setTokenTypeHint("access_token");
if (options.tokenType) {
context.setTokenTypeHint(options.tokenType);
}

if (this.options.authenticateWith === "http_basic_auth") {
context.authenticateWithHTTPBasicAuth(
Expand All @@ -412,7 +417,7 @@ export class OAuth2Strategy<
}

return sendTokenRevocationRequest(
this.options.tokenEndpoint.toString(),
this.options.tokenRevocationEndpoint.toString(),
context,
{ signal: options.signal },
);
Expand Down

0 comments on commit 08b1d26

Please sign in to comment.