0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

refactor(core): update grant comments (#6120)

This commit is contained in:
Gao Sun 2024-06-27 18:50:51 +08:00 committed by GitHub
parent 211c3576d7
commit b1e7f62f79
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,15 +1,14 @@
/** /**
* @overview This file implements the custom `client_credentials` grant which extends the original * @overview This file implements the custom `client_credentials` grant which extends the original
* `client_credentials` grant with the issuing of organization tokens (based on RFC 0001, but for * `client_credentials` grant with the issuing of organization tokens (RFC 0006).
* machine-to-machine apps).
* *
* Note the code is edited from oidc-provider, most parts are kept the same unless it requires * Note the code is edited from oidc-provider, most parts are kept the same unless it requires
* changes for TypeScript or RFC 0001. * changes for TypeScript or RFC 0006.
* *
* For "RFC 0001"-related edited parts, we added comments with `=== RFC 0001 ===` and * For "RFC 0006"-related edited parts, we added comments with `=== RFC 0006 ===` and
* `=== End RFC 0001 ===` to indicate the changes. * `=== End RFC 0006 ===` to indicate the changes.
* *
* @see {@link https://github.com/logto-io/rfcs | Logto RFCs} for more information about RFC 0001. * @see {@link https://github.com/logto-io/rfcs | Logto RFCs} for more information about RFC 0006.
* @see {@link https://github.com/panva/node-oidc-provider/blob/0c52469f08b0a4a1854d90a96546a3f7aa090e5e/lib/actions/grants/client_credentials.js | Original file}. * @see {@link https://github.com/panva/node-oidc-provider/blob/0c52469f08b0a4a1854d90a96546a3f7aa090e5e/lib/actions/grants/client_credentials.js | Original file}.
* *
* @remarks * @remarks
@ -65,7 +64,7 @@ export const buildHandler: (
const dPoP = await dpopValidate(ctx); const dPoP = await dpopValidate(ctx);
/* === RFC 0001 === */ /* === RFC 0006 === */
// The value type is `unknown`, which will swallow other type inferences. So we have to cast it // The value type is `unknown`, which will swallow other type inferences. So we have to cast it
// to `Boolean` first. // to `Boolean` first.
const organizationId = cond(Boolean(params?.organization_id) && String(params?.organization_id)); const organizationId = cond(Boolean(params?.organization_id) && String(params?.organization_id));
@ -85,11 +84,13 @@ export const buildHandler: (
error.statusCode = 403; error.statusCode = 403;
throw error; throw error;
} }
/* === End RFC 0001 === */ /* === End RFC 0006 === */
// Do not check the resource if the organization ID is provided and the resource is not. In this // Do not check the resource if the organization ID is provided and the resource is not. In this
// case, the default resource server will be ignored, and an organization token will be issued. // case, the default resource server will be ignored, and an organization token will be issued.
if (!(organizationId && !params?.resource)) { if (!(organizationId && !params?.resource)) {
// This line is copied from the original file. It checks the resource server according to the
// configuration and parameters, then saves them in `ctx.oidc.resourceServers`.
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
await checkResource(ctx, async () => {}); await checkResource(ctx, async () => {});
} }
@ -134,7 +135,7 @@ export const buildHandler: (
// Issue organization token only if resource server is not present. // Issue organization token only if resource server is not present.
// If it's present, the flow falls into the `checkResource` and `if (resourceServer)` block above. // If it's present, the flow falls into the `checkResource` and `if (resourceServer)` block above.
if (organizationId && !resourceServer) { if (organizationId && !resourceServer) {
/* === RFC 0001 === */ /* === RFC 0006 === */
const audience = buildOrganizationUrn(organizationId); const audience = buildOrganizationUrn(organizationId);
const availableScopes = await queries.organizations.relations.appsRoles const availableScopes = await queries.organizations.relations.appsRoles
.getApplicationScopes(organizationId, client.clientId) .getApplicationScopes(organizationId, client.clientId)
@ -155,7 +156,7 @@ export const buildHandler: (
scope: availableScopes.join(' '), scope: availableScopes.join(' '),
}; };
token.scope = issuedScopes; token.scope = issuedScopes;
/* === End RFC 0001 === */ /* === End RFC 0006 === */
} }
if (client.tlsClientCertificateBoundAccessTokens) { if (client.tlsClientCertificateBoundAccessTokens) {