Skip to content

(cognito): UserPoolClient does not correctly respect authFlows #16236

@kazkansouh

Description

@kazkansouh

I have a simple definition such as:

    const userPoolClient = new UserPoolClient(this, 'MyUserPool', {
      userPool,
      oAuth: {
        callbackUrls: ['http://localhost/callback'],
        flows: {
          authorizationCodeGrant: true,
        },
        scopes: [OAuthScope.OPENID, OAuthScope.PROFILE],
      },
      generateSecret: false,
      authFlows: {
        custom: false,
      },
    });

Notice, that it sets the custom auth flow to to false. However, after deploying this the following is observed in the console:

Screenshot_20210826_102941

I.e. both custom and SRP are enabled without me specifying this.

Cause

I believe the below function is at fault as it only checks if any values are true before setting the CloudFormation property ExplicitAuthFlows.

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'); }
// 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;
}
return authFlows;
}

Possible Solution

Possibly the following:

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

Should be changed to unconditionally push ALLOW_REFRESH_TOKEN_AUTH (as the case props.authFlows is undefined is already handled). I.e., it should be changed to:

authFlows.push('ALLOW_REFRESH_TOKEN_AUTH'); 

This would mean when the user provides a authFlows property the default behaviour will always be replaced, not only if a true value is provided for one of the options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-cognitoRelated to Amazon CognitobugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions