User Management System of abc123 using Unity-Lambda-Cognito
===
#### Author: Po-Wen (Steven) Fang
###### tags: `Dragon Cloud AI`
[TOC]
## Work Flow
Lambda function: abc123_Unity_Cognito
At the Unity frontend, we invoke Lambda function to access to Cognito.

input and output are all JSON format.
Please note that signing up new user requires attributes that are different from previous React/Native UI.
User's information that should be entered includes:
1. username
2. password
3. name
4. gender
5. birthdate
6. address
7. email
8. locale
9. Institute
## Implemented Functions
### Sign up new user
Allows user to create a new account in our system. After signing up, user will receive an email contains the confirmation code.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "SignUp",
"username": "someone@email.com",
"password": "123MyPasswordIsPassword",
"name": "haventfigureoutname",
"gender": "female",
"birthdate": "2020-02-02",
"address": "7F No.270 ZhongXiao east road",
"email": "someone@email.com",
"locale": "Taipei",
"Institute": "NTU"
}
```
* #### intent -- (string)
Should be "SignUp"
* #### username -- (string)
Username is always an email address.
* #### password -- (string)
Length fall between 8 and 256. Should contain at least one upper letter, one lower letter, one number. Special character is not allowed.
* #### name -- (string)
Alternative name
* #### gender -- (string)
"male" or "female"
* #### birthdate -- (string)
Format: "year-mm-dd"
* #### address -- (string)
* #### email -- (string)
Should be the same with username
* #### locale -- (string)
(a list allow user to select?)
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "successfully sign up!"
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
### Confirmation of sign up new user
Users are required to enter the confirmation code sent to their email.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "confirmSignUp",
"username": "someone@email.com",
"ConfirmationCode": "123456"
}
```
* #### intent -- (string)
Should be "confirmSignUp"
* #### username -- (string)
Username is always an email address
* #### ConfirmationCode -- (string)
Confirmation code entered by user, length should always be 6
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "confirmed sign up."
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
### Resend the confirmation code
Users can request to send another confirmation code again.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "resendConfirmationCode",
"username": "someone@email.com"
}
```
* #### intent -- (string)
Should be "login"
* #### username -- (string)
Username is always an email address
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "Confirmation code has been sent again."
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
### User login
User login with a account that already existed in our user pool.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "login",
"username": "someone@email.com",
"password": "123MyPasswordIsPassword"
}
```
* #### intent -- (string)
Should be "login"
* #### username -- (string)
Username is always an email address
* #### password -- (string)
Length fall between 8 and 256. Should contain at least one upper letter, one lower letter, one number. Special character is not allowed.
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": {
"AccessToken": "eyJraWQiOiJrckRcL2l2N2VBeVp",
"ExpiresIn": 3600,
"TokenType": "Bearer",
"RefreshToken": "eyJra324fiOiJrckRcL2l2N2dwaeVp",
"IdToken": "eyJraWQiOiJrawef22l2N2VBeVp"
}
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### AccessToken -- (string)
The access token that allows this specific user to access other function
* #### ExpiresIn -- (int)
The expiration period of the authentication result in seconds
* #### TokenType -- (string)
The token type (does not necessary for our application now)
* #### RefreshToken -- (string)
The refresh token (does not necessary for our application now)
* #### IdToken -- (string)
The ID token (does not necessary for our application now)
---
### Forgot password
A confirmation code will be sent to user's email that is required to change user's password.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "forgotPassword",
"username": "someone@email.com"
}
```
* #### intent -- (string)
Should be "forgotPassword"
* #### username -- (string)
Username is always an email address
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "Confirmation code has been sent."
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
### Confirm forgot password
Confirms the new password set by user.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "confirmForgotPassword",
"ConfirmationCode": "123456",
"password": "NewPassword123",
"username": "someone@email.com"
}
```
* #### intent -- (string)
Should be "confirmForgotPassword"
* #### ConfirmationCode -- (string)
Confirmation code entered by user, length should always be 6
* #### password -- (string)
New password set by user. Length fall between 8 and 256. Should contain at least one upper letter, one lower letter, one number. Special character is not allowed.
* #### username -- (string)
Username is always an email address
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "password has been changed."
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
### Change password
Change a new password, requires previous password.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "changePassword",
"AccessToken": "eyJraWQiOiJrckRcL2l2N2VBeVp",
"PreviousPassword": "123MyPasswordIsPassword",
"ProposedPassword": "NewPassword123"
}
```
* #### intent -- (string)
Should be "changePassword"
* #### AccessToken -- (string)
The access token that received at user login
* #### PreviousPassword -- (string)
Previous password
* #### ProposedPassword -- (string)
New password proposed by user. Length fall between 8 and 256. Should contain at least one upper letter, one lower letter, one number. Special character is not allowed.
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "password has been changed."
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
### Delete user account
Delete this user account in our system.
#### Parameters:
>example input from Unity:
```json=
{
"intent": "deleteUser",
"AccessToken": "eyJraWQiOiJrckRcL2l2N2VBeVp"
}
```
* #### intent -- (string)
Should be "deleteUser"
* #### AccessToken -- (string)
The access token that received at user login
#### Returns:
>example return JSON object:
```json=
{
"statusCode": 200,
"body": "user deleted."
}
```
* #### statusCode -- (int)
200 indicates success, 400 indicates error
* #### body -- (string)
Contains the message indicating action status
---
## User Table in DynamoDB (WIP)
trigger in Cognito
login via dynamoDB?
## References
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html
https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_Operations.html