This repository was archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAuthorization.yml
More file actions
106 lines (97 loc) · 3.13 KB
/
Authorization.yml
File metadata and controls
106 lines (97 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Cognito Authentication
- Resource: UserPool
Type: AWS::Cognito::UserPool
Properties:
AliasAttributes:
- email
- preferred_username
AutoVerifiedAttributes:
- email
EmailVerificationSubject: "Your λ# chat verification code"
Schema:
- Name: email
AttributeDataType: String
Mutable: false
Required: true
UsernameConfiguration:
CaseSensitive: false
UserPoolTags:
"LambdaSharp:Module": !Ref Module::FullName
"LambdaSharp:Stack": !Ref AWS::StackName
- Resource: UserPoolClient
Type: AWS::Cognito::UserPoolClient
Properties:
AllowedOAuthFlows:
- code
AllowedOAuthFlowsUserPoolClient: true
AllowedOAuthScopes:
- openid
CallbackURLs:
- !Ref WebsiteLoginUrl
ExplicitAuthFlows:
- ALLOW_USER_SRP_AUTH
- ALLOW_REFRESH_TOKEN_AUTH
GenerateSecret: false
LogoutURLs:
- !Sub "https://${WebsiteCloudFront.DomainName}/logout"
PreventUserExistenceErrors: ENABLED
RefreshTokenValidity: 7 # days
SupportedIdentityProviders:
- COGNITO
UserPoolId: !Ref Authorization::UserPool
- Resource: UserPoolDomain
Type: AWS::Cognito::UserPoolDomain
Properties:
Domain: !Select [ 2, !Split [ "/", !Ref AWS::StackId ]]
UserPoolId: !Ref Authorization::UserPool
- Variable: Issuer
Value: !GetAtt Authorization::UserPool.ProviderURL
- Variable: ClientId
Value: !Ref Authorization::UserPoolClient
- Variable: UserPoolUri
Value: !Sub "https://${Authorization::UserPoolDomain}.auth.${AWS::Region}.amazoncognito.com"
# WebSocket Authorization
- Resource: JwtAuthorizer
Type: AWS::ApiGatewayV2::Authorizer
Properties:
Name: JwtAuthorizer
ApiId: !Ref Module::WebSocket
AuthorizerType: REQUEST
AuthorizerUri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Authorization::JwtAuthorizerFunction.Arn}/invocations"
AuthorizerCredentialsArn: !GetAtt Authorization::JwtAuthorizerRole.Arn
IdentitySource:
- route.request.querystring.header
- Resource: JwtAuthorizerRole
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName: lambda
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: lambda:invokeFunction
Resource: !GetAtt Authorization::JwtAuthorizerFunction.Arn
- Resource: JwtAuthorizerPermission
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt Authorization::JwtAuthorizerFunction.Arn
Principal: !Sub "apigateway.${AWS::URLSuffix}"
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${Module::WebSocket}/${Module::WebSocket::StageName}/$connect"
- Function: JwtAuthorizerFunction
Description: Authorize WebSocket connection using JWT
Memory: 256
Timeout: 30
Environment:
Issuer: !Ref Authorization::Issuer
Audience: !Ref Authorization::ClientId