Last active
July 12, 2023 12:45
-
-
Save daaru00/85bbaf6d9b92b00f88bd00e960bbaefa to your computer and use it in GitHub Desktop.
Lambda authorizer to check OAuth2 authorization token
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
service: ProtectAPI | |
provider: | |
name: aws | |
runtime: nodejs8.10 | |
stage: dev | |
region: eu-west-1 | |
functions: | |
app: | |
handler: app.handler | |
events: | |
- http: | |
path: /my-protected-path | |
method: GET | |
authorizer: | |
name: authorizer | |
resultTtlInSeconds: 0 | |
identitySource: method.request.header.Authorization | |
type: token | |
authorizer: | |
handler: authorizer.handler | |
environment: | |
COGNITO_REGION: ${opt:region, self:provider.region} | |
COGNITO_USER_POOL_ID: | |
Ref: UserPool | |
COGNITO_CLIENT_ID: | |
Ref: UserPoolClient | |
resources: | |
Resources: | |
UserPool: | |
Type: "AWS::Cognito::UserPool" | |
Properties: | |
UserPoolName: "${self:service}-user-pool" | |
AutoVerifiedAttributes: | |
- "email" | |
Schema: | |
- Name: name | |
AttributeDataType: String | |
Mutable: true | |
Required: true | |
- Name: email | |
AttributeDataType: String | |
Mutable: false | |
Required: true | |
UserPoolClient: | |
Type: "AWS::Cognito::UserPoolClient" | |
Properties: | |
ClientName: "${self:service}-client" | |
GenerateSecret: true | |
ExplicitAuthFlows: | |
- ADMIN_NO_SRP_AUTH | |
UserPoolId: | |
Ref: "UserPool" | |
IdentityPool: | |
Type: "AWS::Cognito::IdentityPool" | |
Properties: | |
IdentityPoolName: "${self:service}Identity" | |
AllowUnauthenticatedIdentities: true | |
CognitoIdentityProviders: | |
- ClientId: | |
Ref: "UserPoolClient" | |
ProviderName: | |
"Fn::GetAtt": ["UserPool", "ProviderName"] | |
IdentityPoolRoleMapping: | |
Type: "AWS::Cognito::IdentityPoolRoleAttachment" | |
Properties: | |
IdentityPoolId: | |
Ref: "IdentityPool" | |
Roles: | |
authenticated: | |
"Fn::GetAtt": ["CognitoAuthorizedRole", "Arn"] |
Hi @leonardoviada,
would definitely be a better solution, this script is older than the JWT parsing library. In fact it would also render node-jose
useless, which it would be nice to replace with aws-jwt-verify
.
The related generatePolicy function remains valid, if there isn't some new, slightly more convenient library there too.
Seems like that's still the default approach, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@daaru00 did you consider https://github.com/awslabs/aws-jwt-verify ?