import { JWK , JWT } from "@panva/jose" ; import { IAuthenticationStrategy , IIdpUser } from "@staticdeploy/core" ; import { has , isString } from "lodash" ; export default class JwtAuthenticationStrategy implements IAuthenticationStrategy { private verifyingKey : JWK . Key ; constructor ( secretOrPublicKey ) { this . verifyingKey = JWK . asKey ( secretOrPublicKey ) ; } async getIdpUserFromAuthToken ( authToken ) { try { const jwt = JWT . verify ( authToken , this . verifyingKey ) ; return has ( jwt , "sub" ) && isString ( jwt . sub ) && has ( jwt , "iss" ) && isString ( jwt . iss ) ? { idp : jwt . iss , id : jwt . sub } : null ; } catch { return null ; } } }