Skip to content

Commit dd10df1

Browse files
authored
fix(cognito): UserPoolDomain.baseUrl() does not return FIPS-compliant url for gov cloud regions (#20200)
This ensures that users in GovCloud can retrieve a URL that works in their region and allows users in us-{east,west}-{1,2} to also use the FIPs endpoints. Partially discussed in #20182. Resolves #12500 ---- ### All Submissions: * [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3e0393e commit dd10df1

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

packages/@aws-cdk/aws-cognito/lib/user-pool-domain.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,21 @@ export class UserPoolDomain extends Resource implements IUserPoolDomain {
152152

153153
/**
154154
* The URL to the hosted UI associated with this domain
155+
*
156+
* @param options options to customize baseUrl
155157
*/
156-
public baseUrl(): string {
158+
public baseUrl(options?: BaseUrlOptions): string {
157159
if (this.isCognitoDomain) {
158-
return `https://${this.domainName}.auth.${Stack.of(this).region}.amazoncognito.com`;
160+
const authDomain = 'auth' + (options?.fips ? '-fips' : '');
161+
return `https://${this.domainName}.${authDomain}.${Stack.of(this).region}.amazoncognito.com`;
159162
}
160163
return `https://${this.domainName}`;
161164
}
162165

163166
/**
164167
* The URL to the sign in page in this domain using a specific UserPoolClient
165168
* @param client [disable-awslint:ref-via-interface] the user pool client that the UI will use to interact with the UserPool
166-
* @param options options to customize the behaviour of this method.
169+
* @param options options to customize signInUrl.
167170
*/
168171
public signInUrl(client: UserPoolClient, options: SignInUrlOptions): string {
169172
let responseType: string;
@@ -175,14 +178,26 @@ export class UserPoolDomain extends Resource implements IUserPoolDomain {
175178
throw new Error('signInUrl is not supported for clients without authorizationCodeGrant or implicitCodeGrant flow enabled');
176179
}
177180
const path = options.signInPath ?? '/login';
178-
return `${this.baseUrl()}${path}?client_id=${client.userPoolClientId}&response_type=${responseType}&redirect_uri=${options.redirectUri}`;
181+
return `${this.baseUrl(options)}${path}?client_id=${client.userPoolClientId}&response_type=${responseType}&redirect_uri=${options.redirectUri}`;
179182
}
180183
}
181184

185+
/**
186+
* Options to customize the behaviour of `baseUrl()`
187+
*/
188+
export interface BaseUrlOptions {
189+
/**
190+
* Whether to return the FIPS-compliant endpoint
191+
*
192+
* @default return the standard URL
193+
*/
194+
readonly fips?: boolean;
195+
}
196+
182197
/**
183198
* Options to customize the behaviour of `signInUrl()`
184199
*/
185-
export interface SignInUrlOptions {
200+
export interface SignInUrlOptions extends BaseUrlOptions {
186201
/**
187202
* Where to redirect to after sign in
188203
*/

packages/@aws-cdk/aws-cognito/test/user-pool-domain.test.ts

+56
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,62 @@ describe('User Pool Client', () => {
164164
Template.fromStack(stack).resourceCountIs('AWS::Cognito::UserPoolDomain', 0);
165165
});
166166

167+
describe('baseUrl', () => {
168+
test('returns the expected standard URL', () => {
169+
// GIVEN
170+
const stack = new Stack();
171+
const pool = new UserPool(stack, 'Pool');
172+
const domain = pool.addDomain('Domain', {
173+
cognitoDomain: {
174+
domainPrefix: 'cognito-domain-prefix',
175+
},
176+
});
177+
178+
// WHEN
179+
const baseUrl = domain.baseUrl();
180+
181+
// THEN
182+
expect(stack.resolve(baseUrl)).toEqual({
183+
'Fn::Join': [
184+
'', [
185+
'https://',
186+
{ Ref: 'PoolDomainCFC71F56' },
187+
'.auth.',
188+
{ Ref: 'AWS::Region' },
189+
'.amazoncognito.com',
190+
],
191+
],
192+
});
193+
});
194+
195+
test('returns the expected FIPS-compliant endpoint URL', () => {
196+
// GIVEN
197+
const stack = new Stack();
198+
const pool = new UserPool(stack, 'Pool');
199+
const domain = pool.addDomain('Domain', {
200+
cognitoDomain: {
201+
domainPrefix: 'cognito-domain-prefix',
202+
},
203+
});
204+
205+
// WHEN
206+
const baseUrl = domain.baseUrl({ fips: true });
207+
208+
// THEN
209+
expect(stack.resolve(baseUrl)).toEqual({
210+
'Fn::Join': [
211+
'', [
212+
'https://',
213+
{ Ref: 'PoolDomainCFC71F56' },
214+
'.auth-fips.',
215+
{ Ref: 'AWS::Region' },
216+
'.amazoncognito.com',
217+
],
218+
],
219+
});
220+
});
221+
});
222+
167223
describe('signInUrl', () => {
168224
test('returns the expected URL', () => {
169225
// GIVEN

0 commit comments

Comments
 (0)