Skip to content

Commit

Permalink
fix(api-security): load permissions immediately after authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 25, 2024
1 parent 53aba1c commit 26f650a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions packages/api-security/src/createSecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export const createSecurity = async (config: SecurityConfig): Promise<Security>
}

permissionsLoader = new Promise<SecurityPermission[]>(async resolve => {
// Authorizers often need to query business-related data, and since the identity is not yet
// authorized, these operations can easily trigger a NOT_AUTHORIZED error.
// To avoid this, we disable permission checks (assume `full-access` permissions) for
// the duration of the authorization process.
for (const authorizer of authorizers) {
const result = await authorizer();
if (Array.isArray(result)) {
Expand All @@ -65,11 +61,12 @@ export const createSecurity = async (config: SecurityConfig): Promise<Security>
return {
...authentication,
config,
async authenticate(token: string): Promise<void> {
async authenticate(this: Security, token: string): Promise<void> {
await authentication.authenticate(token);
if (authentication.getIdentity()) {
authenticationToken = token;
}
await this.withoutAuthorization(() => loadPermissions());
},
onBeforeLogin: createTopic("security.onBeforeLogin"),
onLogin: createTopic("security.onLogin"),
Expand Down

0 comments on commit 26f650a

Please sign in to comment.