Skip to content

Commit

Permalink
refactor: rename config opt to authenticateIntrospect & authenticateR…
Browse files Browse the repository at this point in the history
…evoke
  • Loading branch information
jasonraimondi committed Aug 12, 2024
1 parent 36f0182 commit cf41704
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
1 change: 0 additions & 1 deletion .idea/ts-oauth2-server.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions docs/docs/authorization_server/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ The default configuration is great for most users. You might not need to tweak a

The authorization server has a few optional settings with the following default values;

| Option | Type | Default | Details |
| --------------------------------- | ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `requiresPKCE` | boolean | true | PKCE is enabled by default and recommended for all users. To support a legacy client without PKCE, disable this option. [[Learn more]][requires-pkce] |
| `requiresS256` | boolean | true | Disabled by default. If you want to require all clients to use S256, you can enable that here. [[Learn more]][requires-s256] |
| `notBeforeLeeway` | number | 0 | Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. |
| `tokenCID` | "id" or "name" | "id" | Sets the JWT `accessToken.cid` to either the `client.id` or `client.name`.<br /><br />In 3.x the default is **"id"**, in v2.x the default was **"name"**. [[Learn more]][token-cid] |
| `issuer` | string \| undefined | undefined | Sets the JWT `accessToken.iss` to this value. |
| `introspectWithClientCredentials` | boolean | true | Authorize [the /introspect endpoint](../endpoints/introspect.mdx) using `client_credentials`, this requires users to pass in a valid client_id and client_secret (or Authorization header) |
| `revokeWithClientCredentials` | boolean | true | Authorize [the /revoke endpoint](../endpoints/revoke.mdx) using `client_credentials`, this requires users to pass in a valid client_id and client_secret (or Authorization header) |
| Option | Type | Default | Details |
| ------------------------ | ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `requiresPKCE` | boolean | true | PKCE is enabled by default and recommended for all users. To support a legacy client without PKCE, disable this option. [[Learn more]][requires-pkce] |
| `requiresS256` | boolean | true | Disabled by default. If you want to require all clients to use S256, you can enable that here. [[Learn more]][requires-s256] |
| `notBeforeLeeway` | number | 0 | Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value MUST be a number containing a NumericDate value. |
| `tokenCID` | "id" or "name" | "id" | Sets the JWT `accessToken.cid` to either the `client.id` or `client.name`.<br /><br />In 3.x the default is **"id"**, in v2.x the default was **"name"**. [[Learn more]][token-cid] |
| `issuer` | string \| undefined | undefined | Sets the JWT `accessToken.iss` to this value. |
| `authenticateIntrospect` | boolean | true | Authorize the [/introspect](../endpoints/introspect.mdx) endpoint using `client_credentials`, this requires users to pass in a valid client_id and client_secret (or Authorization header) <br /><br />In 4.x the default is **true**, in v3.x the default was **false**. |
| `authenticateRevoke` | boolean | true | Authorize the [/revoke](../endpoints/revoke.mdx) endpoint using `client_credentials`, this requires users to pass in a valid client_id and client_secret (or Authorization header) <br /><br />In 4.x the default is **true**, in v3.x the default was **false**. |

```ts
type AuthorizationServerOptions = {
Expand All @@ -25,8 +25,8 @@ type AuthorizationServerOptions = {
notBeforeLeeway: 0;
tokenCID: "id" | "name";
issuer: undefined;
introspectWithClientCredentials: boolean;
revokeWithClientCredentials: boolean;
authenticateIntrospect: boolean;
authenticateRevoke: boolean;
};
```

Expand Down
4 changes: 2 additions & 2 deletions src/authorization_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export interface AuthorizationServerOptions {
tokenCID: "id" | "name";
issuer?: string;
scopeDelimiter: string;
introspectWithClientCredentials: boolean;
revokeWithClientCredentials: boolean;
authenticateIntrospect: boolean;
authenticateRevoke: boolean;
}

export type EnableableGrants =
Expand Down
2 changes: 1 addition & 1 deletion src/grants/auth_code.grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class AuthCodeGrant extends AbstractAuthorizedGrant {
async respondToRevokeRequest(req: RequestInterface): Promise<ResponseInterface> {
req.body["grant_type"] = this.identifier;

if (this.options.revokeWithClientCredentials) await this.validateClient(req);
if (this.options.authenticateRevoke) await this.validateClient(req);

const token = this.getRequestParameter("token", req);

Expand Down
4 changes: 2 additions & 2 deletions src/grants/client_credentials.grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ClientCredentialsGrant extends AbstractGrant {
async respondToIntrospectRequest(req: RequestInterface): Promise<ResponseInterface> {
req.body["grant_type"] = this.identifier;

if (this.options.introspectWithClientCredentials) await this.validateClient(req);
if (this.options.authenticateIntrospect) await this.validateClient(req);

const { parsedToken, oauthToken, expiresAt, tokenType } = await this.tokenFromRequest(req);

Expand Down Expand Up @@ -60,7 +60,7 @@ export class ClientCredentialsGrant extends AbstractGrant {
async respondToRevokeRequest(req: RequestInterface): Promise<ResponseInterface> {
req.body["grant_type"] = this.identifier;

if (this.options.revokeWithClientCredentials) await this.validateClient(req);
if (this.options.authenticateRevoke) await this.validateClient(req);

let { oauthToken } = await this.tokenFromRequest(req);

Expand Down
4 changes: 2 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export const DEFAULT_AUTHORIZATION_SERVER_OPTIONS: AuthorizationServerOptions =
tokenCID: "id",
issuer: undefined,
scopeDelimiter: " ",
introspectWithClientCredentials: true,
revokeWithClientCredentials: true,
authenticateIntrospect: true,
authenticateRevoke: true,
};
8 changes: 4 additions & 4 deletions test/e2e/authorization_server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ describe("authorization_server", () => {
inMemoryDatabase.clients[client.id] = client;
});

describe("without option introspectWithClientCredentials=false", () => {
describe("without option authenticateIntrospect=false", () => {
it("does not require client credentials", async () => {
authorizationServer = new AuthorizationServer(
inMemoryClientRepository,
inMemoryAccessTokenRepository,
inMemoryScopeRepository,
new JwtService("secret-key"),
{
introspectWithClientCredentials: false,
authenticateIntrospect: false,
},
);

Expand Down Expand Up @@ -548,15 +548,15 @@ describe("authorization_server", () => {
inMemoryDatabase.clients[client.id] = client;
});

describe("without option revokeWithClientCredentials=false", () => {
describe("without option authenticateRevoke=false", () => {
it("does not require client credentials", async () => {
authorizationServer = new AuthorizationServer(
inMemoryClientRepository,
inMemoryAccessTokenRepository,
inMemoryScopeRepository,
new JwtService("secret-key"),
{
revokeWithClientCredentials: false,
authenticateRevoke: false,
},
);

Expand Down

0 comments on commit cf41704

Please sign in to comment.