Package: b-cfn-custom-userpool-authorizer
B.CfnCustomUserPoolAuthorizerAn AWS CDK resource that mimics original UserPoolAuthorizer resource.DescriptionThis is a custom user pool authorizer used to protect API endpoints.
It has exactly the same functionality and purpose as the originalUserPoolAuthorizer.
The main reason why you would want to use this custom authorizer instead
of a default one - is that this custom authorizer can resolve user pool
region, id, and client id from SSM parameters (AWS Systems Manager Parameter Store).
This way your stacks no longer need a dependency to a stack containing user pool instance.RemarksBiomapasaims to modernise life-science industry by sharing its IT knowledge with other companies and the community.
This is an open source library intended to be used by anyone.
Improvements and pull requests are welcome.Related technologyPython3AWS CDKAWS CloudFormationAWS CognitoAWS Cognito User PoolAWS API GatewayAWS API Gateway AuthorizerAssumptionsThis project assumes you are an expert in infrastructure-as-code via AWS CloudFormation and AWS CDK.
You must clearly understand how AWS API Gateway endpoints are protected with Authorizers / Custom Authorizers
and how it is managed via CloudFormation or CDK. You must also understand the pain-points
of stack dependencies and dependencies between microservices in general (which this package aims to solve).Excellent knowledge in IaaC (Infrastructure as a Code) principles.Excellent knowledge in Cognito, User Pool, API Gateway, Authorizers.Good experience in AWS CDK and AWS CloudFormation.Good Python skills and basis of OOP.Useful sourcesAWS CDK:https://docs.aws.amazon.com/cdk/api/latest/docs/aws-construct-library.htmlAWS CloudFormation:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.htmlAPI Gateway with CloudFormation:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.htmlAWS Cognito use pool:https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools.htmlAWS Custom Authorizers:https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.htmlInstallBefore installing this library, ensure you have these tools setup:Python / PipAWS CDKDockerTo install this project from source run:pip install .Or you can install it from a PyPi repository:pip install b-cfn-custom-userpool-authorizerUsage & Examplesfromaws_cdkimportStackfromaws_cdk.aws_cognitoimportUserPool,UserPoolClientfromaws_cdk.aws_apigatewayv2importCfnApifromb_cfn_custom_userpool_authorizer.config.user_pool_configimportUserPoolConfigfromb_cfn_custom_userpool_authorizer.user_pool_custom_authorizerimportUserPoolCustomAuthorizer# Create user pool and client.pool=UserPool(...)client=UserPoolClient(...)# Create an API Gateway API.api=CfnApi(...)# Create custom authorizer and use it in your endpoints (CfnRoute).authorizer=UserPoolCustomAuthorizer(scope=Stack(...),name='MyCustomAuthorizer',api=api,user_pool_config=UserPoolConfig(user_pool_id=pool.user_pool_id,user_pool_region=pool.stack.region,user_pool_client_id=client.user_pool_client_id))TestingThis package has integration tests based onpytest.
To run tests simply run:pytest b_cfn_custom_userpool_authorizer_test/integration/testsContributionFound a bug? Want to add or suggest a new feature?
Contributions of any kind are gladly welcome.
You may contact us directly, create a pull-request or an issue in GitHub platform.
Lets modernize the world together.Release history2.0.0Upgrade CDK support from v1 to v2.Upgrade GitHub pipelines checkout version from v2 to v3.Upgrade biomapas/cicd-full image version to 5.0.0.1.0.0Upgrade dependencies to breaking versions.0.1.2Make dependency range more strict.0.1.1Add the ability to use a Bearer Token.Add JWT claims to authorizer output.0.1.0Add property to expose authorization type for API Gateway APIs.0.0.16Add more tests to handle completely broken jwt tokens like "aaa.bbb.ccc".0.0.14Simplify logging with pytest.0.0.13Update B.LambdaLayerCommon dependency.0.0.12Add more integration tests.Update b_lambda_layer_common dependency.0.0.11Add readme.0.0.10Add tests.0.0.9Enable caching.0.0.8Fix testing configuration.0.0.7Success! Authorizer can now successfully authorize tokens.0.0.6First attempt to verify cognito user pool JWT token.0.0.5Still work in progress. Requests and tests work.Checking the actual access token - in progress.0.0.3Work in progress. Added integration testing files.0.0.1Initial build.