-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalized the migration flows and added the appropriate curl commands
- Loading branch information
Vladimir Budilov
committed
Jan 24, 2018
1 parent
df0e4fe
commit a5af2a0
Showing
10 changed files
with
248 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
It's a set of [AWS Lambda](https://aws.amazon.com/lambda/) functions that, once deployed using the provided [SAM](https://github.com/awslabs/serverless-application-model) template, act as | ||
an [Amazon Cognito](https://aws.amazon.com/cognito/) proxy. | ||
|
||
*Note: In most cases you should consider using the SDKs directly on the client, without using a proxy, especially | ||
if your business usecase allows it* | ||
*Note: In most cases you should consider using the SDKs directly on the client side, without using a proxy, especially | ||
if your business use-case allows it* | ||
|
||
### Why was this project created? | ||
* QuickStart for any custom IdP --> Cognito migration service | ||
|
@@ -32,38 +32,57 @@ CognitoAutoconfirmUserParameter | Setting this value to 'true' will auto-confirm | |
# Package it | ||
aws cloudformation package --template-file sam.yaml --s3-bucket code.budilovv --output-template-file /tmp/UpdatedSAMTemplate.yaml | ||
# Deploy it | ||
aws cloudformation deploy --template-file /tmp/UpdatedSAMTemplate.yaml --stack-name auth-stack --parameter-overrides RegionParameter=REGION CognitoUserPoolIdParameter=REGION_PGSbCVZ7S CognitoAppClientIdParameter=hikoo0i7jmt9lplrd2j0n9jqo --capabilities CAPABILITY_IAM | ||
aws cloudformation deploy --template-file /tmp/UpdatedSAMTemplate.yaml --stack-name auth-stack \ | ||
--parameter-overrides \ | ||
RegionParameter=REGION \ | ||
CognitoUserPoolIdParameter=REGION_xxxxxxxxx \ | ||
CognitoAppClientIdParameter=xxxxxxxxxxxxxxxxxxxxx \ | ||
CognitoAutoconfirmUserParameter=true \ | ||
--capabilities CAPABILITY_IAM | ||
``` | ||
|
||
### Test the Flows | ||
|
||
##### Sign Up | ||
``` | ||
curl -XPOST 'https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/Prod/signup' --header "username: [email protected]" --header "password: Cognito&&1" | ||
``` | ||
export [email protected] | ||
export SAMPLE_PASSWORD=myPassword**^1 | ||
export REGION=us-east-1 | ||
export API_GATEWAY_ID= | ||
##### Sign In | ||
``` | ||
curl -XPOST 'https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/Prod/signin' --header "username: [email protected]" --header "password: Cognito&&1" | ||
``` | ||
# Signup | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/signup' --header "username: $SAMPLE_EMAIL" --header "password: $SAMPLE_PASSWORD" | ||
##### Password Reset | ||
``` | ||
curl -XPOST 'https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/Prod/password/reset' --header "idToken: AAAAAAAAAAAAaa" | ||
``` | ||
# Confirm SignUp | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/confirmsignup' --header "username: $SAMPLE_EMAIL" --header "confirmationCode: CONFIRMATION_CODE" | ||
##### Refresh | ||
``` | ||
curl -XPOST 'https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/Prod/refresh' --header "refreshToken: BBBBBBBBBBBBBBb" | ||
``` | ||
# SignIn | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/admin/signin' --header "username: $SAMPLE_EMAIL" --header "password: $SAMPLE_PASSWORD" | ||
##### Check for token validity | ||
``` | ||
curl -XPOST 'https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/Prod/token/valid' --header "idToken: AAAAAAAAAAAAaa" | ||
``` | ||
##### Delete User | ||
``` | ||
curl -XDELETE 'https://API_GATEWAY_ID.execute-api.REGION.amazonaws.com/Prod/user' --header "idToken: AAAAAAAAAAAAaa" | ||
# Refresh Tokens | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/admin/refresh' --header "refreshToken: JWT_REFRESH_TOKEN" | ||
# Check if the token is valid | ||
curl -XGET 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/token/valid' --header "idToken: JWT_ID_TOKEN" | ||
# Reset Password | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/password/reset' --header "username: $SAMPLE_EMAIL" | ||
# Create a new password | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/password/confirm' --header "username: $SAMPLE_EMAIL" --header "password: $SAMPLE_PASSWORD" --header "confirmationCode: CONFIRMATION_CODE" | ||
# Update User Attribute | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/admin/user/attribute' --header "idToken: JWT_ID_TOKEN" --header "attributeName: name" --header "attributeValue: Vladimir Budilov" | ||
# Delete User | ||
curl -XDELETE 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/admin/user' --header "idToken: JWT_ID_TOKEN" | ||
# Resend Confirmation Code (can be used only when verification is turned on) | ||
curl -XPOST 'https://$API_GATEWAY_ID.execute-api.$REGION.amazonaws.com/Prod/resendcode' --header "username: $SAMPLE_EMAIL" | ||
# Confirm SignUp (can be used only when verification is turned on) | ||
curl -XPOST 'https://60ii5ih8b4.execute-api.us-east-1.amazonaws.com/Prod/confirmsignup' --header "username: $SAMPLE_EMAIL" --header "confirmationCode: CONFIRMATION_CODE" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/com/budilov/cognito/lambda/CognitoConfirmForgotPasswordLambda.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.budilov.cognito.lambda | ||
|
||
import com.amazonaws.services.lambda.runtime.Context | ||
import com.amazonaws.services.lambda.runtime.RequestHandler | ||
import com.budilov.cognito.services.CognitoService | ||
import com.google.gson.Gson | ||
|
||
/** | ||
* @author Vladimir Budilov | ||
*/ | ||
class CognitoConfirmForgotPasswordLambda : RequestHandler<ApiGatewayRequest.Input, | ||
ApiGatewayResponse> { | ||
|
||
val cognito = CognitoService() | ||
|
||
override fun handleRequest(request: ApiGatewayRequest.Input?, | ||
context: Context?): ApiGatewayResponse { | ||
|
||
val username = request?.headers?.get("username") | ||
val password = request?.headers?.get("password") | ||
|
||
val confirmationCode = request?.headers?.get("confirmationCode") | ||
|
||
var status = 400 | ||
var response = "" | ||
|
||
if (username != null && password != null && confirmationCode != null) { | ||
response = Gson().toJson(cognito.confirmForgotPassword(username = username, confirmationCode = confirmationCode, password = password)) | ||
status = 200 | ||
} | ||
|
||
return ApiGatewayResponse(statusCode = status, body = response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.