diff --git a/account-kit/signer/src/client/index.ts b/account-kit/signer/src/client/index.ts index 0b1387fe03..5435a13887 100644 --- a/account-kit/signer/src/client/index.ts +++ b/account-kit/signer/src/client/index.ts @@ -511,7 +511,7 @@ export class AlchemySignerWebClient extends BaseSignerClient let scope: string; let claims: string | undefined; if (providedScope) { - scope = providedScope; + scope = addOpenIdIfAbsent(providedScope); claims = providedClaims; } else { if (isCustomProvider) { @@ -670,6 +670,17 @@ function resolveRelativeUrl(url: string): string { return a.href; } +/** + * "openid" is a required scope in the OIDC protocol. Insert it if the user + * forgot. + * + * @param {string} scope scope param which may be missing "openid" + * @returns {string} scope which most definitely contains "openid" + */ +function addOpenIdIfAbsent(scope: string): string { + return scope.match(/\bopenid\b/) ? scope : `openid ${scope}`; +} + /** * This error is thrown when the OAuth flow is cancelled because the auth popup * window was closed.