Skip to content

Commit

Permalink
fix(cognito): authFlows require refreshToken in all scenarios (#10561)
Browse files Browse the repository at this point in the history
refreshToken always allowed when authFlows present in UserPoolClient

BREAKING CHANGE: `refreshToken` property is now removed from
UserPoolClient. It will be included if any other `authFlow` is enabled.

closes #7625


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
ayush987goyal authored Sep 30, 2020
1 parent fbd48b2 commit c0a3cb4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
22 changes: 11 additions & 11 deletions packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ export interface AuthFlow {
* @default false
*/
readonly userSrp?: boolean;

/**
* Enable authflow to refresh tokens
* @default false
*/
readonly refreshToken?: boolean;
}

/**
Expand Down Expand Up @@ -343,12 +337,18 @@ export class UserPoolClient extends Resource implements IUserPoolClient {
}

private configureAuthFlows(props: UserPoolClientProps): string[] | undefined {
if (!props.authFlows) return undefined;

const authFlows: string[] = [];
if (props.authFlows?.userPassword) { authFlows.push('ALLOW_USER_PASSWORD_AUTH'); }
if (props.authFlows?.adminUserPassword) { authFlows.push('ALLOW_ADMIN_USER_PASSWORD_AUTH'); }
if (props.authFlows?.custom) { authFlows.push('ALLOW_CUSTOM_AUTH'); }
if (props.authFlows?.userSrp) { authFlows.push('ALLOW_USER_SRP_AUTH'); }
if (props.authFlows?.refreshToken) { authFlows.push('ALLOW_REFRESH_TOKEN_AUTH'); }
if (props.authFlows.userPassword) { authFlows.push('ALLOW_USER_PASSWORD_AUTH'); }
if (props.authFlows.adminUserPassword) { authFlows.push('ALLOW_ADMIN_USER_PASSWORD_AUTH'); }
if (props.authFlows.custom) { authFlows.push('ALLOW_CUSTOM_AUTH'); }
if (props.authFlows.userSrp) { authFlows.push('ALLOW_USER_SRP_AUTH'); }

// refreshToken should always be allowed if authFlows are present
if (authFlows.length > 0) {
authFlows.push('ALLOW_REFRESH_TOKEN_AUTH');
}

if (authFlows.length === 0) {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ userpool.addClient('myuserpoolclient', {
authFlows: {
adminUserPassword: true,
custom: true,
refreshToken: true,
userPassword: true,
userSrp: true,
},
Expand Down
21 changes: 20 additions & 1 deletion packages/@aws-cdk/aws-cognito/test/user-pool-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe('User Pool Client', () => {
authFlows: {
adminUserPassword: true,
custom: true,
refreshToken: true,
userPassword: true,
userSrp: true,
},
Expand All @@ -95,6 +94,26 @@ describe('User Pool Client', () => {
});
});

test('ExplicitAuthFlows makes refreshToken true by default', () => {
// GIVEN
const stack = new Stack();
const pool = new UserPool(stack, 'Pool');

// WHEN
pool.addClient('Client', {
authFlows: {
userSrp: true,
},
});

expect(stack).toHaveResourceLike('AWS::Cognito::UserPoolClient', {
ExplicitAuthFlows: [
'ALLOW_USER_SRP_AUTH',
'ALLOW_REFRESH_TOKEN_AUTH',
],
});
});

test('AllowedOAuthFlows are correctly named', () => {
// GIVEN
const stack = new Stack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class CognitoStack extends Stack {
generateSecret: true,
authFlows: {
userPassword: true,
refreshToken: true,
},
oAuth: {
flows: {
Expand Down

0 comments on commit c0a3cb4

Please sign in to comment.