Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use shared cognito pool #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking "Sign up for GitHub", you agree to our terms of service and privacy statement. We'll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
OlegRakovich merged 1 commit into master from refactoring/use-shared-user-pool
Jun 7, 2025
Merged

Use shared cognito pool #44

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions code/frontend/src/Auth/Authenticator.ts
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './tools';

export class Authenticator {
constructor(private authUrl: string, private redirectUri: string, private api: AuthApi) {}
constructor(private authUrl: string, private redirectUri: string, private clientId: string, private api: AuthApi) {}

getStoredToken = (): Promise => {
return this.getToken();
Expand All @@ -18,7 +18,7 @@ export class Authenticator {
const token = await this.getToken();

if (!token) {
redirectToAuthPage(this.authUrl, this.redirectUri);
redirectToAuthPage(this.authUrl, this.redirectUri, this.clientId);
return null;
}

Expand Down
6 changes: 4 additions & 2 deletions code/frontend/src/Auth/tools/redirectToAuthPage.ts
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function redirectToAuthPage(authUrl: string, redirectUri: string) {
window.location.replace(`${authUrl}/login?redirect_uri=${redirectUri}&response_type=code&scope=openid`);
export function redirectToAuthPage(authUrl: string, redirectUri: string, clientId: string) {
window.location.replace(
`${authUrl}/login?redirect_uri=${redirectUri}&response_type=code&scope=openid&client_id=${clientId}&state=/`
);
}
2 changes: 1 addition & 1 deletion code/frontend/src/DependeciesInjection/hooks/useDependencies .ts
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useDependencies = () => {
const { devAuthenticator, passwordsApi } = useMemo(() => {
const authApi = new AuthApi(config.clientId, config.redirectUri, config.auth);
return {
devAuthenticator: new Authenticator(config.auth, config.redirectUri, authApi),
devAuthenticator: new Authenticator(config.auth, config.redirectUri, config.clientId, authApi),
passwordsApi: new PasswordsApi(config.backend)
};
}, [config]);
Expand Down
3 changes: 2 additions & 1 deletion code/frontend/vite.config.ts
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import path from 'path';

export default defineConfig({
build: {
outDir: '../../.local/Frontend'
outDir: '../../.local/Frontend',
emptyOutDir: true
},
resolve: {
alias: {
Expand Down
14 changes: 8 additions & 6 deletions deploy/deploy-frontend-code.ps1
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ param(
$Local = "$PSScriptRoot/../.local"

function Publish-Code {
& npm @(
'run'
'--prefix'
"${PSScriptRoot}/../code/frontend"
'build'
)
Push-Location "${PSScriptRoot}/../code/frontend"

npm run build

Pop-Location

Copy-Item "$Local/deploy/FrontendConfig${Stage}.json" -Destination "$Local/Frontend/config.json"
}

function Deploy-Code {
Expand All @@ -21,6 +22,7 @@ function Deploy-Code {
'sync'
"$Local/Frontend"
"s3://$bucketName"
'--delete'
)
}

Expand Down
2 changes: 1 addition & 1 deletion deploy/templates/BackendLambda.yml
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Resources:
CognitoClientAppId:
Fn::ImportValue: !Sub "ServerlessPass${Stage}UserPoolClientId"
CognitoUserPoolId:
Fn::ImportValue: !Sub "ServerlessPass${Stage}UserPoolId"
Fn::ImportValue: !Sub "StaticsoftExternalUsers${Stage}UserPoolId"
DynamoDbTableNamePrefix: !Sub "ServerlessPass${Stage}"
CrossOriginDomains:
Fn::ImportValue: !Sub "ServerlessPass${Stage}CrossOriginDomains"
Expand Down
41 changes: 6 additions & 35 deletions deploy/templates/BackendServices.yml
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,17 @@ Resources:
- DomainName: !Ref DomainName
HostedZoneId: !Ref DomainHostedZoneId
ValidationMethod: DNS
UserPool:
Type: AWS::Cognito::UserPool
Properties:
AccountRecoverySetting:
RecoveryMechanisms:
- Name: verified_email
Priority: 1
AutoVerifiedAttributes:
- email
Policies:
PasswordPolicy:
MinimumLength: 8
RequireLowercase: true
RequireNumbers: true
RequireSymbols: true
RequireUppercase: true
TemporaryPasswordValidityDays: 1
UsernameAttributes:
- email
UsernameConfiguration:
CaseSensitive: false
UserPoolName: !Sub "${Alias.Value}Users"
VerificationMessageTemplate:
DefaultEmailOption: CONFIRM_WITH_LINK
EmailMessageByLink: Please click the link below to verify your email address.
{##Verify email##}
EmailSubjectByLink: Email verification is required
UserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ClientName: BackendUserPoolClient
ClientName: ServerlessPassBackendClient
ExplicitAuthFlows:
- ALLOW_REFRESH_TOKEN_AUTH
- ALLOW_USER_PASSWORD_AUTH
SupportedIdentityProviders:
- COGNITO
UserPoolId: !Ref UserPool
UserPoolId:
Fn::ImportValue: !Sub "StaticsoftExternalUsers${Stage}UserPoolId"
TokenValidityUnits:
AccessToken: days
IdToken: days
Expand Down Expand Up @@ -119,7 +93,8 @@ Resources:
Action:
- cognito-idp:AdminInitiateAuth
- cognito-idp:ListUsers
Resource: !GetAtt UserPool.Arn
Resource:
Fn::ImportValue: !Sub "StaticsoftExternalUsers${Stage}UserPoolArn"
LambdaFunctionRole:
Type: AWS::IAM::Role
Properties:
Expand Down Expand Up @@ -285,7 +260,7 @@ Resources:
RestApiId: !Ref ApiGateway
Type: COGNITO_USER_POOLS
ProviderARNs:
- !Sub "arn:aws:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/${UserPool}"
- Fn::ImportValue: !Sub "StaticsoftExternalUsers${Stage}UserPoolArn"
IdentitySource: method.request.header.Authorization
AuthorizerResultTtlInSeconds: 3600
ApiGatewayDomain:
Expand All @@ -312,10 +287,6 @@ Outputs:
Value: !GetAtt LambdaFunctionRole.Arn
Export:
Name: !Sub "ServerlessPass${Stage}LambdaFunctionRoleArn"
UserPoolId:
Value: !Ref UserPool
Export:
Name: !Sub "ServerlessPass${Stage}UserPoolId"
UserPoolClientId:
Value: !Ref UserPoolClient
Export:
Expand Down
30 changes: 2 additions & 28 deletions deploy/templates/FrontendServices.yml
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ Resources:
- DomainName: !Ref DomainName
HostedZoneId: !Ref DomainHostedZoneId
ValidationMethod: DNS
AuthCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: !Sub "auth.${DomainName}"
DomainValidationOptions:
- DomainName: !Sub "auth.${DomainName}"
HostedZoneId: !Ref DomainHostedZoneId
ValidationMethod: DNS
ArtifactsBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Expand Down Expand Up @@ -125,40 +117,22 @@ Resources:
- openid
CallbackURLs:
- !Sub https://${DomainName}
ClientName: FrontendUserPoolClient
ClientName: ServerlessPassFrontendClient
ExplicitAuthFlows:
- ALLOW_USER_PASSWORD_AUTH
- ALLOW_REFRESH_TOKEN_AUTH
GenerateSecret: false
SupportedIdentityProviders:
- COGNITO
UserPoolId:
Fn::ImportValue: !Sub "ServerlessPass${Stage}UserPoolId"
Fn::ImportValue: !Sub "StaticsoftExternalUsers${Stage}UserPoolId"
TokenValidityUnits:
AccessToken: days
IdToken: days
RefreshToken: days
RefreshTokenValidity: 3650
AccessTokenValidity: 1
IdTokenValidity: 1
AuthenticationDomain:
Type: AWS::Cognito::UserPoolDomain
Properties:
CustomDomainConfig:
CertificateArn: !Ref AuthCertificate
Domain: !Sub "auth.${DomainName}"
UserPoolId:
Fn::ImportValue: !Sub "ServerlessPass${Stage}UserPoolId"
AuthDNSRecord:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref DomainHostedZoneId
Name: !Sub "auth.${DomainName}"
AliasTarget:
DNSName: !GetAtt AuthenticationDomain.CloudFrontDistribution
EvaluateTargetHealth: false
HostedZoneId: Z2FDTNDATAQYW2
Type: A
Outputs:
ArtifactsBucketName:
Value: !Ref ArtifactsBucket
Expand Down