diff --git a/packages/core-app-api/report.api.md b/packages/core-app-api/report.api.md index 6af171ea4d..09119d8f8d 100644 --- a/packages/core-app-api/report.api.md +++ b/packages/core-app-api/report.api.md @@ -566,8 +566,10 @@ export class OAuth2 getProfile(options?: AuthRequestOptions): Promise; // (undocumented) static normalizeScopes( - scopeTransform: (scopes: string[]) => string[], scopes?: string | string[], + options?: { + scopeTransform: (scopes: string[]) => string[]; + }, ): Set; // (undocumented) sessionState$(): Observable; diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts index 7318d30382..c03176f8b6 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts @@ -85,10 +85,9 @@ export default class OAuth2 providerInfo: { idToken: res.providerInfo.idToken, accessToken: res.providerInfo.accessToken, - scopes: OAuth2.normalizeScopes( + scopes: OAuth2.normalizeScopes(res.providerInfo.scope, { scopeTransform, - res.providerInfo.scope, - ), + }), expiresAt: res.providerInfo.expiresInSeconds ? new Date(Date.now() + res.providerInfo.expiresInSeconds * 1000) : undefined, @@ -169,7 +168,9 @@ export default class OAuth2 scope?: string | string[], options?: AuthRequestOptions, ) { - const normalizedScopes = OAuth2.normalizeScopes(this.scopeTransform, scope); + const normalizedScopes = OAuth2.normalizeScopes(scope, { + scopeTransform: this.scopeTransform, + }); const session = await this.sessionManager.getSession({ ...options, scopes: normalizedScopes, @@ -201,8 +202,8 @@ export default class OAuth2 * @public */ public static normalizeScopes( - scopeTransform: (scopes: string[]) => string[], scopes?: string | string[], + options?: { scopeTransform: (scopes: string[]) => string[] }, ): Set { if (!scopes) { return new Set(); @@ -212,6 +213,10 @@ export default class OAuth2 ? scopes : scopes.split(/[\s|,]/).filter(Boolean); - return new Set(scopeTransform(scopeList)); + const transformedScopes = options + ? options.scopeTransform(scopeList) + : scopeList; + + return new Set(transformedScopes); } } diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts index cfed4d4714..82578f835e 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts @@ -70,10 +70,9 @@ describe('OAuth2CustomAuthConnector', () => { providerInfo: { idToken: res.providerInfo.idToken, accessToken: res.providerInfo.accessToken, - scopes: OAuth2.normalizeScopes( + scopes: OAuth2.normalizeScopes(res.providerInfo.scope, { scopeTransform, - res.providerInfo.scope, - ), + }), expiresAt: res.providerInfo.expiresInSeconds ? new Date(Date.now() + res.providerInfo.expiresInSeconds * 1000) : undefined,