Skip to content

Commit

Permalink
fix(@aws-amplify/auth): Fix OAuth multiple scopes (#5850)
Browse files Browse the repository at this point in the history
* Fix multiple scopes query string generation
  • Loading branch information
elorzafe authored May 21, 2020
1 parent e71fee5 commit f89e545
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/auth/src/OAuth/OAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 } : {}),
Expand Down

0 comments on commit f89e545

Please sign in to comment.