From f89e545a93f370f0ce91b437514f833b03c6202b Mon Sep 17 00:00:00 2001 From: Francisco Rodriguez Date: Wed, 20 May 2020 21:16:39 -0700 Subject: [PATCH] fix(@aws-amplify/auth): Fix OAuth multiple scopes (#5850) * Fix multiple scopes query string generation --- packages/auth/src/OAuth/OAuth.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/auth/src/OAuth/OAuth.ts b/packages/auth/src/OAuth/OAuth.ts index 8295ed8e4fb..96159e11998 100644 --- a/packages/auth/src/OAuth/OAuth.ts +++ b/packages/auth/src/OAuth/OAuth.ts @@ -55,9 +55,18 @@ export default class OAuth { this._urlOpener = config.urlOpener || launchUri; this._config = config; this._cognitoClientId = cognitoClientId; + + if (!this.isValidScopes(scopes)) + throw Error('scopes must be a String Array'); this._scopes = scopes; } + private isValidScopes(scopes: string[]) { + return ( + Array.isArray(scopes) && scopes.every(scope => typeof scope === 'string') + ); + } + public oauthSignIn( responseType = 'code', domain: string, @@ -81,12 +90,14 @@ export default class OAuth { const code_challenge = this._generateChallenge(pkce_key); const code_challenge_method = 'S256'; + const scopesString = this._scopes.join(' '); + const queryString = Object.entries({ redirect_uri: redirectSignIn, response_type: responseType, client_id: clientId, identity_provider: provider, - scope: this._scopes, + scope: scopesString, state, ...(responseType === 'code' ? { code_challenge } : {}), ...(responseType === 'code' ? { code_challenge_method } : {}),