Skip to content

Commit

Permalink
fix(core): set oidc access denied error code to 403 (#5725)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie authored Apr 17, 2024
1 parent d48094b commit d545303
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/forty-grapes-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@logto/core': patch
---

Fix OIDC AccessDenied error code to 403.

This error may happen when you try to grant an access token to a user lacking the required permissions, especially when granting for orgnization related resources. The error code should be 403 instead of 400.
8 changes: 6 additions & 2 deletions packages/core/src/oidc/grants/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ export const buildHandler: (
if (organizationId) {
// Check membership
if (!(await queries.organizations.relations.users.exists(organizationId, account.accountId))) {
throw new AccessDenied('user is not a member of the organization');
const error = new AccessDenied('user is not a member of the organization');
error.statusCode = 403;
throw error;
}

// Check if the organization is granted (third-party application only) by the user
Expand All @@ -242,7 +244,9 @@ export const buildHandler: (
organizationId
))
) {
throw new AccessDenied('organization access is not granted to the application');
const error = new AccessDenied('organization access is not granted to the application');
error.statusCode = 403;
throw error;
}
}
/* === End RFC 0001 === */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const grantErrorContaining = (code: string, description: string, status = 400) =
const accessDeniedError = grantErrorContaining(
'oidc.access_denied',
'user is not a member of the organization',
400
403
);

const issuer = defaultConfig.endpoint + '/oidc';
Expand Down

0 comments on commit d545303

Please sign in to comment.