Skip to content

Commit da673f7

Browse files
Merge pull request #64 from jmstio/main
Login with Cognito
2 parents 10bb887 + 5125987 commit da673f7

File tree

4 files changed

+656
-4
lines changed

4 files changed

+656
-4
lines changed

CustomIdentityComponent/README.md

+74
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
+ [GET /login-with-apple-id](#get-login-with-apple-id)
1111
+ [GET /login-with-google-play](#get-login-with-google-play)
1212
+ [GET /login-with-facebook](#get-login-with-facebook)
13+
+ [GET /login-with-cognito](#get-login-with-cognito)
1314

1415
The custom identity component is a serverless solution that manages a JSON Web Key Set (JWKS) with key rotation and publicly available configuration and public keys through an Amazon CloudFront endpoint. It supports integration with Steam, Sign in with Apple, Google Play, and Facebook, and can be extended with custom code to more providers such as console platforms.
1516

@@ -37,6 +38,8 @@ Optionally, you can add integrations to identity providers by modifying `CustomI
3738
* Set `const googlePlayClientSecretArn` to the Arn of a Secrets Manager secret containing your Client Secret for the Web application client (see [Google Play developer docs](https://developers.google.com/games/services/console/enabling) for details). You can create a secret with the AWS CLI: `aws secretsmanager create-secret --name MyGooglePlayClientSecret --description "Google Play client secret" --secret-string "YOURCLIENTSECRET"`
3839
* __Facebook__
3940
* Set `const facebookAppId` to the App ID of your Facebook application in developer.facebook.com. You can find this under "Basic Settings" for the app.
41+
* __Cognito__
42+
* Set `const cognito = "true"`
4043

4144
When you set a non empty value for one of these App ID:s, the CDK stack will automatically deploy required endpoints and resources for that platform.
4245

@@ -214,4 +217,75 @@ The API integrations are built into the SDK:s provided for Unreal, Unity, and Go
214217
> | `200` | `{'facebook_id': facebook_id,'user_id': user_id,'auth_token': auth_token,'refresh_token': refresh_token, 'auth_token_expires_in' :auth_token_expires_in,'refresh_token_expires_in' : refresh_token_expires_in}` |
215218
> | `401` | Multiple errors: could not create a validate user |
216219
220+
### GET /login-with-cognito
217221

222+
`GET /login-with-cognito`
223+
224+
**Parameters**
225+
226+
> | name | required | description |
227+
> |-----------|-----------|--------------------------------------------------------------------------------|
228+
> | `link_to_existing_user` | No | Set this to `Yes` for linking the Cognito identity to existing user. Requires also the `auth_token` field to be set. |
229+
> | `access_token` | No | Provide an existing access_token for a logged in user when linking Cognito identity to existing user. Requires also the `link_to_existing_user` to be set. |
230+
> | `auth_code` | No | The auth code returned to the clien after the guest auth flow complete. |
231+
232+
233+
**Body**
234+
> | name | required | description |
235+
> |-----------|-----------|--------------------------------------------------------------------------------|
236+
> | `username` | No | When logging in with Cognito, you always need to provide a valid username |
237+
> | `password` | No | When logging in with Cognito, you always need to provide a valid password |
238+
> | `email` | No | When signing up, you always need to provide a valid email address |
239+
> | `signin` | No | Set this to `True` for signing in with Cognito |
240+
> | `signup` | No | Set this to `True` for signing up with Cognito |
241+
> | `signup_confirmation_code` | No | Set this to the signup confirmation code that will be emailed to a user after they sign up with Cognito for first time. |
242+
> | `signout` | No | Set this to `True` when signing out |
243+
> | `forgot_password` | No | Set this to `True` when initiating forgot password flow |
244+
> | `reset_password` | No | Set this to `True` for requesting a code to reset password that will be emailed to user |
245+
> | `reset_password_code` | No | Set this to the reset password code that will be emailed to the user when once they have initiated the forgot password flow. |
246+
247+
**Responses**
248+
249+
> | http code | response |
250+
> |---------------|---------------------------------------------------------------------|
251+
> | `200` | `{'cognito__id': cognito_user_id,'user_id': user_id,'auth_token': auth_token,'refresh_token': refresh_token, 'auth_token_expires_in' :auth_token_expires_in,'refresh_token_expires_in' : refresh_token_expires_in}` |
252+
> | `401` | Multiple errors: could not create a validate user |
253+
254+
**Example POST requests with curl**
255+
256+
**Sign up as a new user**
257+
258+
```bash
259+
curl -XPOST -d '{
260+
"body": {
261+
"username": "Username",
262+
"password": "Password12345#",
263+
"email": "email@domain.com",
264+
"signup": "True"
265+
}
266+
}' 'https://abcdefg.execute-api.us-west-2.amazonaws.com/prod/login-with-cognito'
267+
````
268+
269+
**Confirm sign up with a confirmation code**
270+
271+
```bash
272+
curl -XPOST -d '{
273+
"body": {
274+
"username": "Username",
275+
"confirmation_code": "1234567",
276+
"signup_confirmation_code": "True"
277+
}
278+
}' 'https://abcdefg.execute-api.us-west-2.amazonaws.com/prod/login-with-cognito'
279+
```
280+
281+
**Sign in with a confirmed user**
282+
283+
```bash
284+
curl -XPOST -d '{
285+
"body": {
286+
"username": "Username",
287+
"password": "Password12345#",
288+
"signin": "True"
289+
}
290+
}' 'https://abcdefg.execute-api.us-west-2.amazonaws.com/prod/login-with-cognito'
291+
```

CustomIdentityComponent/bin/custom_identity_component.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const googlePlayClientSecretArn = ""
3333
// Set this to the App ID of your Facebook app created in developer.facebook.com, found under "Basic Settings"
3434
// An empty value "" required to Not deploy the Facebook login endpoint
3535
const facebookAppId = ""
36+
// Set this vale to true if you want to provision Amazon Cognito as your identity provider
37+
const cognito = ""
3638

3739
const app = new cdk.App();
3840
var identityComponentStack = new CustomIdentityComponentStack(app, 'CustomIdentityComponentStack', {
@@ -44,7 +46,8 @@ var identityComponentStack = new CustomIdentityComponentStack(app, 'CustomIdenti
4446
googlePlayClientId: googlePlayClientId,
4547
googlePlayAppId: googlePlayAppid,
4648
googlePlayClientSecretArn: googlePlayClientSecretArn,
47-
facebookAppId: facebookAppId
49+
facebookAppId: facebookAppId,
50+
cognito: cognito
4851
});
4952

5053
// Apply all the tags in the tags object to the stack
@@ -58,5 +61,6 @@ var identityComponentStack = new CustomIdentityComponentStack(app, 'CustomIdenti
5861
// Suppressions
5962
NagSuppressions.addStackSuppressions(identityComponentStack, [
6063
{ id: 'AwsSolutions-APIG4', reason: 'The API has to be publicly accessible as it is built for user login and authentication for custom identities.' },
61-
{ id: 'AwsSolutions-COG4', reason: 'The API cannot use Cognito User Pools as it is an API built for login and authentication for custom identities.' }
64+
{ id: 'AwsSolutions-COG4', reason: 'The API cannot use Cognito User Pools as it is an API built for login and authentication for custom identities.' },
65+
{ id: 'AwsSolutions-COG3', reason: 'AdvancedSecurityMode is not mandatory for this solution.' }
6266
]);

0 commit comments

Comments
 (0)