UNPKG

@indiekit/endpoint-auth

Version:

IndieAuth authentication and authorization endpoint for Indiekit. Grants and verifies access tokens and authenticates users.

17 lines (14 loc) 530 B
import { createHash } from "node:crypto"; /** * Verify PKCE (Proof Key for Code Exchange) code * @param {string} verifier - Code verifier * @param {string} challenge - Code challenge * @param {string} [challengeMethod] - Code challenge method * @returns {boolean} - Code challenge result */ export const verifyCode = (verifier, challenge, challengeMethod = "sha256") => { const base64Digest = createHash(challengeMethod) .update(verifier) .digest("base64url"); return challenge === base64Digest.toString(); };