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
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
//### EXAMPLE: import the function
import { TokenAuthorizerJwtFunction } from "@cloudy-with-a-chance-of-meatballs/cdk-lambda-token-authorizer-jwt";
//### END
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', {});
//### EXAMPLE: validation (see avj json schema validation)
const tokensSchema = JSON.stringify({
properties:{
iss: {
enum: ["THE_ISSUER_WHICH_NEEDS_TO_MATCH"]
},
sub: {
enum: ["THE_SUB..."]
}
},
additionalProperties: true
});
//### END: validation
//### EXAMPLE: init the function
const tokenAuthFunction = new TokenAuthorizerJwtFunction(this, 'lambdaFunctionName', {
environment: {
// PROVIDE VARIABLES
TOKEN_AUTHORIZER_JWKS_URI: 'https://example.auth0.com/.well-known/jwks.json',
TOKEN_AUTHORIZER_JWKS_KID: 'SOME_KID_FROM_JWKS_RESPONSE',
// OR
TOKEN_AUTHORIZER_JWT_VERIFICATION_SECRET: 'A_PUBLIC_KEY_OR_SYMETRIC_SECRET',
//TOKEN PAYLOAD VALIDATION
TOKEN_AUTHORIZER_JWT_VALIDATOR_SCHEMA_JSON: tokensSchema
}
});
//### END
const tokenAuthorizer = new apigateway.TokenAuthorizer(this, 'tokenAuthorizerName', {
//### EXAMPLE: use as handler
handler: tokenAuthFunction
//### END
});
// ...
const someMethod = SOMEAPIRESOURCE.addMethod("GET", SOMETARGETINTEGRATION, { authorizer: tokenAuthorizer });
}
}
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.24.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a7c5c844461a422996555d11c7d9347c94d26c786d919387f2865799e63d2b1 |
|
MD5 | 58ad3282d38afd76b4004fb6eb49885c |
|
BLAKE2b-256 | f715e46765960a5b0a489ad8c3798b0eabaf6a6ff144b85b9d3c59201e95910c |
Close
Hashes for cloudy_with_a_chance_of_meatballs.cdk_lambda_token_authorizer_jwt-0.0.24-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de0d54bcdc23a21a2ab5b3a985b7a9476be357d762807be487a52570da2ae8a6 |
|
MD5 | 6b37a618582cf8dd54dff5295a0afb90 |
|
BLAKE2b-256 | 0c9838ffa8ea26f4b00ed819b36cb1f8af5c74298d6b351bdf993d77afdc86c8 |