Skip to content

Commit 9873ce2

Browse files
committed
Make SSO login in UI opt-in: only basic by default
1 parent d60df3d commit 9873ce2

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

cloud/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DOMAIN_NAME=your.domain
22
HOSTED_ZONE_ID=YOUR_AWS_HOSTED_ZONE_ID
33

4-
# Enable Azure IdP
5-
#IDP_NAME=azure
4+
# Enable Azure IdP for SSO (using SAML)
5+
#IDP_NAME=AZURE
66
#AZURE_APPLICATION_ID=[your-azure-application-id]
77
#AZURE_TENANT_ID=[your-azure-tenant-id]

cloud/lib/auth-stack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class AuthStack extends Stack {
8181
if (!AZURE_APPLICATION_ID) throw new Error('Missing env var AZURE_APPLICATION_SECRET');
8282
if (!AZURE_TENANT_ID) throw new Error('Missing env var AZURE_TENANT_ID');
8383
const idp = new UserPoolIdentityProviderSaml(this, generateResourceId('azure-idp'), {
84-
name: 'Azure',
84+
name: 'AZURE',
8585
userPool,
8686
metadata: UserPoolIdentityProviderSamlMetadata.url(
8787
`https://login.microsoftonline.com/${AZURE_TENANT_ID}/federationmetadata/2007-06/federationmetadata.xml?appid=${AZURE_APPLICATION_ID}`

cloud/lib/pipeline-stack.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
BuildEnvironmentVariable,
3-
BuildEnvironmentVariableType,
4-
BuildSpec,
5-
} from 'aws-cdk-lib/aws-codebuild';
1+
import { BuildEnvironmentVariableType, BuildSpec } from 'aws-cdk-lib/aws-codebuild';
62
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
73
import { IBucket } from 'aws-cdk-lib/aws-s3';
84
import { Stack, StackProps } from 'aws-cdk-lib/core';
@@ -41,7 +37,7 @@ export class PipelineStack extends Stack {
4137

4238
const hostBucketName = generateResourceId('host-bucket');
4339

44-
const identityProviderEnv: Record<string, BuildEnvironmentVariable> =
40+
const identityProviderEnv =
4541
process.env.IDP_NAME?.toUpperCase() === 'AZURE'
4642
? {
4743
IDP_NAME: {
@@ -57,7 +53,7 @@ export class PipelineStack extends Stack {
5753
value: 'AZURE_TENANT_ID',
5854
},
5955
}
60-
: {};
56+
: undefined;
6157

6258
const pipeline = new CodePipeline(this, generateResourceId('pipeline'), {
6359
synth: new ShellStep('Synth', {
@@ -138,7 +134,8 @@ export class PipelineStack extends Stack {
138134
env: {
139135
CI: 'true',
140136
VITE_AUTH_PROVIDER: 'cognito',
141-
},
137+
VITE_COGNITO_IDP: identityProviderEnv?.IDP_NAME.value,
138+
} as Record<string, string>,
142139
envFromCfnOutputs: {
143140
VITE_UI_DOMAIN: appStage.domainName,
144141
VITE_BACKEND_URL: appStage.backendUrl,

frontend/.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
VITE_BACKEND_URL=http://localhost:3000/api
22

3-
# Currently only AWS Cognito is supported for remote authorization
4-
# If you're ok with AWS, Cognito can integrate with external identity providers
3+
# Currently only AWS Cognito is supported for remote authn/authz
4+
# Note that Cognito can integrate with external identity providers
55
#VITE_AUTH_PROVIDER=cognito
66
#VITE_COGNITO_REDIRECT_URL=https://YOUR_DOMAIN
77
#VITE_COGNITO_USERPOOL_ID=YOUR_USERPOOL_ID

frontend/src/components/AuthProviders/CognitoAuthenticatedApp.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const usernameFormField = {
3232
},
3333
};
3434

35+
const ssoProvider = import.meta.env.VITE_COGNITO_IDP;
36+
3537
Amplify.configure({
3638
Auth: {
3739
Cognito: {
@@ -40,7 +42,7 @@ Amplify.configure({
4042
loginWith: {
4143
oauth: {
4244
domain: import.meta.env.VITE_COGNITO_USERPOOL_DOMAIN,
43-
providers: [{ custom: 'Azure' }],
45+
providers: ssoProvider ? [{ custom: ssoProvider }] : undefined,
4446
redirectSignIn: [import.meta.env.VITE_COGNITO_REDIRECT_URL],
4547
redirectSignOut: [import.meta.env.VITE_COGNITO_REDIRECT_URL],
4648
responseType: 'code',
@@ -114,7 +116,7 @@ function WelcomeHeader() {
114116
return (
115117
<>
116118
<CustomHeader className="welcome-header" heading="Welcome to SpyLogic" />
117-
<SignInSelector />
119+
{ssoProvider ? <SignInSelector /> : <BasicSignIn />}
118120
</>
119121
);
120122
}
@@ -142,6 +144,7 @@ function CustomHeader({
142144
);
143145
}
144146

147+
// NOTE: Currently only Azure SSO is supported
145148
function SignInSelector() {
146149
return (
147150
<Tabs
@@ -157,7 +160,7 @@ function SignInSelector() {
157160
{
158161
label: 'Single Sign On (SSO)',
159162
value: 'sso',
160-
content: <SSOSignIn />,
163+
content: <AzureSignIn />,
161164
},
162165
]}
163166
/>
@@ -256,11 +259,11 @@ function BasicSignIn() {
256259
);
257260
}
258261

259-
function SSOSignIn() {
262+
function AzureSignIn() {
260263
function signIn() {
261264
void signInWithRedirect({
262265
provider: {
263-
custom: 'Azure',
266+
custom: 'AZURE',
264267
},
265268
});
266269
// TODO Catch login errors, e.g. someone without SL SSO access tries their luck

frontend/src/components/AuthProviders/CognitoAuthenticator.css

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@
151151
display: block;
152152
}
153153

154-
[data-amplify-authenticator] [data-amplify-form].basic-login-form {
154+
[data-amplify-authenticator]
155+
.amplify-tabs__panel
156+
[data-amplify-form].basic-login-form {
155157
padding-bottom: 0;
156158
}
157159

@@ -392,8 +394,12 @@
392394
}
393395

394396
[data-amplify-authenticator] .form-header,
395-
[data-amplify-authenticator] [data-amplify-form].basic-login-form,
396-
[data-amplify-authenticator] [data-amplify-form].sso-login-form {
397+
[data-amplify-authenticator]
398+
.amplify-tabs__panel
399+
[data-amplify-form].basic-login-form,
400+
[data-amplify-authenticator]
401+
.amplify-tabs__panel
402+
[data-amplify-form].sso-login-form {
397403
margin: 0 -2rem;
398404
}
399405

@@ -416,8 +422,12 @@
416422
}
417423

418424
[data-amplify-authenticator] .form-header,
419-
[data-amplify-authenticator] [data-amplify-form].basic-login-form,
420-
[data-amplify-authenticator] [data-amplify-form].sso-login-form {
425+
[data-amplify-authenticator]
426+
.amplify-tabs__panel
427+
[data-amplify-form].basic-login-form,
428+
[data-amplify-authenticator]
429+
.amplify-tabs__panel
430+
[data-amplify-form].sso-login-form {
421431
margin: 0 -1.5rem;
422432
}
423433
}
@@ -454,8 +464,12 @@
454464
}
455465

456466
[data-amplify-authenticator] .form-header,
457-
[data-amplify-authenticator] [data-amplify-form].basic-login-form,
458-
[data-amplify-authenticator] [data-amplify-form].sso-login-form {
467+
[data-amplify-authenticator]
468+
.amplify-tabs__panel
469+
[data-amplify-form].basic-login-form,
470+
[data-amplify-authenticator]
471+
.amplify-tabs__panel
472+
[data-amplify-form].sso-login-form {
459473
margin: 0 -1rem;
460474
}
461475
}

frontend/src/vite-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface ImportMetaEnv {
77
readonly VITE_COGNITO_USERPOOL_CLIENT: string;
88
readonly VITE_COGNITO_USERPOOL_DOMAIN: string;
99
readonly VITE_COGNITO_REDIRECT_URL: string;
10+
readonly VITE_COGNITO_IDP: string;
1011
}
1112

1213
interface ImportMeta {

0 commit comments

Comments
 (0)