@cloudy-with-a-chance-of-meatballs/cdk-lambda-token-authorizer-jwt
Project description
CDK Lambda TokenAuthorizer JWT
Add a lambda function to your project which can be used as a apigateway token authorizer
Install
TypeScript
npm install @cloudy-with-a-chance-of-meatballs/cdk-lambda-token-authorizer-jwt
yarn add @cloudy-with-a-chance-of-meatballs/cdk-lambda-token-authorizer-jwt
Python
pip install cloudy-with-a-chance-of-meatballs.cdk-lambda-token-authorizer-jwt
Usage
- JWT Token handling: The token verfification is done via https://github.com/auth0/node-jsonwebtoken, the jwks fetcher is using https://github.com/auth0/node-jwks-rsa. The implementation per default verifies the token and if given the expiration.
- JWT Payload: Any verification of the token payload must be done over injecting a json schema for validation using https://ajv.js.org/json-type-definition.html.
- Protocols: main/API.md#iauthorizeroptions
- Example usage with Rest Apigateway
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import { TokenAuthorizerJwtFunction } from '@cloudy-with-a-chance-of-meatballs/cdk-lambda-token-authorizer-jwt';
export class HelloworldStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const api = new apigateway.RestApi(this, 'ApiName', {});
const tokenAuthFunction = new TokenAuthorizerJwtFunction(this, 'fnName', {...});
const tokenAuthorizer = new apigateway.TokenAuthorizer(this, 'fnNameApiGwAuthorizer', {
handler: tokenAuthFunction // use the TokenAuthorizerJwtFunction
});
const someMethod = api.someresource.addMethod("GET", some_target_integration, {
authorizer: tokenAuthorizer
});
}
}
- Validation
const myValidation = { properties:{ iss: { enum: ['my_trusted_iss'] } }};
new TokenAuthorizerJwtFunction(stack, 'example-stack', { authorizerOptions: {
tokenPayloadJsonSchema: JSON.stringify(myValidation)
}});
- Using JWKS
new TokenAuthorizerJwtFunction(stack, 'example-stack', { authorizerOptions: {
jwks: {
uri: 'https://example.auth0.com/.well-known/jwks.json';
kid: 'REEyM0FBMDhFQkQ5QjY4Q0YzRjVGNzQ5OTU3RjUzN0FEREFFNzJGMg'
}
}});
- Using asymmetric algorithms, e.g. public key
const myPublicKeyOneliner = '-----BEGIN PUBLIC KEY---\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuTfz7kpJHPrmcmgx4Xf4GMoM2kK4mh\nMpSOW3qu1zZA1wfMHV8PS0Kds0nXMB6mmHk/Ke1\Et68aEspQRIn1aLcCAwEAAQ==\n-----END PUBLIC KEY-----';
new TokenAuthorizerJwtFunction(stack, 'example-stack', { authorizerOptions: {
secret: myPublicKeyOneliner
}});
- Using symmetric algorithms, same key for sign and verify :warning:
Attention: the key might be exposed during deploy, in the runtime etc.
const mySymmetricSecret = 'sharedSecret';
new TokenAuthorizerJwtFunction(stack, 'example-stack', { authorizerOptions: {
secret: mySymmetricSecret
}});
🍻
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for cloudy-with-a-chance-of-meatballs.cdk-lambda-token-authorizer-jwt-0.0.31.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 073ce0aa402dc43b552b70cddacfbe4411f35a994a242fd23781a8ddf5c93095 |
|
MD5 | e3539c8958b58fd13406f82f3586bafd |
|
BLAKE2b-256 | f2ce48e02c4752c4c052807bf02982b1a2a6a7c8917155f7a8b1986e9352fcc6 |
Close
Hashes for cloudy_with_a_chance_of_meatballs.cdk_lambda_token_authorizer_jwt-0.0.31-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad6d7b9034d3b4430ef1718cc16982be061946c85e2fe71bffbae520c3129976 |
|
MD5 | e236d1797a4e9ee6a16a2b3a84f6fc72 |
|
BLAKE2b-256 | 08dfc315a396087d8977bff43ea2b3a04130ad290571b9e4b785061c6cf84105 |