Created
December 12, 2022 20:51
-
-
Save fl0wo/97a1c9a7c9c00181b4e4398ca557f5e2 to your computer and use it in GitHub Desktop.
Stytch token integration and side code
This file contains hidden or 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
| export const getStytchTokenFromSessionIdLambdaIntegration = ( | |
| stack: Construct, | |
| id:string, | |
| options:InfrastructureOptions) => { | |
| const getToken = new NodejsFunction(stack, id, { | |
| architecture: Architecture.ARM_64, | |
| entry: `${__dirname}/token.ts`, | |
| logRetention: RetentionDays.ONE_WEEK, | |
| timeout: Duration.minutes(1), | |
| memorySize: 256, | |
| initialPolicy: [ | |
| new PolicyStatement({ | |
| actions: ["ssm:GetParameter","ssm:DeleteParameter"], | |
| resources: ["*"], | |
| }), | |
| ], | |
| environment:{ | |
| ENV: options.environ | |
| } | |
| }); | |
| return getToken; | |
| } |
This file contains hidden or 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
| export const whenJwtExpiresLocal = (token: string) => { | |
| try{ | |
| const obj = parseJwt(token); | |
| return whenJwtExpiresMs(obj); | |
| }catch (e){ | |
| Logger.ERROR(e); | |
| Logger.ERROR('ERROR DURING authenticateJwtLocal WITH ' + token); | |
| return null; | |
| } | |
| } | |
| export function whenJwtExpiresMs(payload: ParsedJwtSession) { | |
| const expAt = new Date(payload["https://stytch.com/session"].expires_at).getTime(); | |
| const now = new Date().getTime(); | |
| return expAt - now; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment