Function verifyJWT

  • verify JWT (JSON Web Token)

    Parameters

    • sJWT: string

      JWT string to verify

    • keyobjOrString: string | CryptoKey

      key for verification. CryptoKey object, PKCS#8 PEM public key or HMAC hexadecimal key string

    • verifyOption: JWTVerifyOption

      verify parameters

    Returns Promise<boolean>

    true if successfully verified

    Throws

    Error if JWT can't be verified

    See

    Example

    const key = await getHMACKey("hmacSHA256", "12ab...");
    await verifyJWT("eyJhb...", key, {
    alg: ["HS256", "HS384"],
    iss: ["https://jwt-idp.example.com"],
    sub: ["mailto:mike@example.com", "mailto:joe@example.com"],
    aud: ["http://foo1.com"],
    jti: "id123456",
    }) -> true/false
    await verifyJWT("eyJ...", "-----BEGIN PUBLIC...", {...}) -> true/false