This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cognito.yml
161 lines (152 loc) · 4.99 KB
/
cognito.yml
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
CognitoDomain:
Type: String
Description: subdomain portion of the cognito domain
CustomResourceStackName:
Type: String
Description: stack name where custom resource lambda arns are exported from
Default: ""
CallbackURLs:
Type: CommaDelimitedList
Description: A list of callback URLs (e.g. for each environment) for Cognito user pool settings
LogoutURLs:
Type: CommaDelimitedList
Description: A list of Logout URLs (e.g. for each environment) for Cognito user pool settings
ManifestPresent:
Type: String
Description: Boolean value of whether manifest from Azure has been received and deployed
Default: "true"
LoadBalancerListenerArn:
Type: String
Description: ARN of your ALB listener (must be HTTPS protocol to authenticate with Cognito in load balancer)
Default: ""
Conditions:
HaveManifest:
Fn::Equals: ["true", !Ref ManifestPresent]
HaveLoadBalancer:
Fn::Not:
- Fn::Equals: ["", !Ref LoadBalancerListenerArn]
Resources:
ClientUserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: !Sub "${CognitoDomain}-client-user-pool"
Schema:
- Name: name
AttributeDataType: String
Mutable: true
Required: true
- Name: email
AttributeDataType: String
Mutable: true
Required: true
- Name: groups
AttributeDataType: String
Mutable: true
Required: false
UsernameAttributes:
- email
ClientUserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: !Sub "${CognitoDomain}-client-user-pool-client"
GenerateSecret: true
UserPoolId: !Ref ClientUserPool
UserPoolClientSettings:
Type: 'Custom::CognitoUserPoolClientSettings'
Properties:
ServiceToken:
Fn::ImportValue: !Sub "${CustomResourceStackName}CustomUserPoolClientSettingsArn"
UserPoolId: !Ref ClientUserPool
UserPoolClientId: !Ref ClientUserPoolClient
SupportedIdentityProviders:
- Fn::If:
- HaveManifest
- !Ref UserPoolIdentityProvider
- !Ref AWS::NoValue
CallbackURLs: !Ref CallbackURLs
LogoutURLs: !Ref LogoutURLs
AllowedOAuthFlowsUserPoolClient: true
AllowedOAuthFlows:
- code
- implicit
AllowedOAuthScopes:
- openid
- email
UserPoolDomain:
Type: 'Custom::CognitoUserPoolDomain'
Properties:
ServiceToken:
Fn::ImportValue: !Sub "${CustomResourceStackName}CustomUserPoolDomainArn"
UserPoolId: !Ref ClientUserPool
Domain: !Ref CognitoDomain
RandomParam: 1
UserPoolResourceServer:
Type: 'Custom::CognitoUserPoolResourceServer'
Properties:
ServiceToken:
Fn::ImportValue: !Sub "${CustomResourceStackName}CustomUserPoolResourceServerArn"
ResourceServer:
UserPoolId:
!Ref ClientUserPool
Identifier: !Sub "https://${CognitoDomain}.yoursite.com"
Name: !Ref CognitoDomain
Scopes:
- ScopeName: customscope
ScopeDescription: your own custom scopes
UserPoolIdentityProvider:
Type: 'Custom::CognitoUserPoolIdentityProvider'
Condition: HaveManifest
Properties:
ServiceToken:
Fn::ImportValue: !Sub "${CustomResourceStackName}CustomUserPoolIdentProvArn"
MetadataFile:
!Sub "${CognitoDomain}.xml"
ProviderName:
AzureSSO
UserPoolId:
!Ref ClientUserPool
AttributeMapping:
name: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name
email: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress
groups: http://schemas.microsoft.com/ws/2008/06/identity/claims/groups
LoadBalancerListenerRuleCognito:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Condition: HaveLoadBalancer
Properties:
ListenerArn:
Fn::ImportValue: !Ref LoadBalancerListenerArn
Conditions:
- Field: path-pattern
Values:
- "*"
Priority: 120
Actions:
- AuthenticateCognitoConfig:
OnUnauthenticatedRequest: authenticate
SessionCookieName: AWSELBAuthSessionCookie
UserPoolArn: !GetAtt ClientUserPool.Arn
UserPoolClientId: !Ref ClientUserPoolClient
UserPoolDomain: !Ref CognitoDomain
Type: authenticate-cognito
Order: 10
- Type: fixed-response
FixedResponseConfig:
ContentType: text/plain
MessageBody: "Congratulations! Authenticated."
StatusCode: "200"
Order: 20
Outputs:
UserPoolDomain:
Value: !Ref CognitoDomain
Export:
Name: !Sub "${AWS::StackName}UserPoolDomain"
UserPoolArn:
Value: !GetAtt ClientUserPool.Arn
Export:
Name: !Sub "${AWS::StackName}UserPoolArn"
UserPoolClientId:
Value: !Ref ClientUserPoolClient
Export:
Name: !Sub "${AWS::StackName}UserPoolClientId"