Authorization is not authentication
#An access token proves your app may call the API; it is not proof of who is using your site. To sign users in, request the openid scope and validate the id_token: check its ES256 signature against /oauth/jwks, iss, aud (your client ID), exp and the nonce you sent. Discovery metadata is at /.well-known/openid-configuration.
GET https://ozvault.lol/.well-known/openid-configurationValidate the ID token
#Use a maintained JOSE library. sub is a pairwise identifier: stable for a given user in your app, different in every other app, and unrelated to the user's Discord ID. Use it as your user key.
// npm i jose
import { createRemoteJWKSet, jwtVerify } from "jose";
const JWKS = createRemoteJWKSet(new URL("https://ozvault.lol/oauth/jwks"));
const { payload } = await jwtVerify(tokens.id_token, JWKS, {
issuer: "https://ozvault.lol",
audience: process.env.OZVAULT_CLIENT_ID,
algorithms: ["ES256"],
});
if (payload.nonce !== savedNonce) throw new Error("nonce mismatch");
// payload.sub: a stable identifier for this user, unique to your application# pip install "pyjwt[crypto]"
import jwt
jwks = jwt.PyJWKClient("https://ozvault.lol/oauth/jwks")
key = jwks.get_signing_key_from_jwt(tokens["id_token"])
claims = jwt.decode(tokens["id_token"], key.key, algorithms=["ES256"],
audience=CLIENT_ID, issuer="https://ozvault.lol")
assert claims["nonce"] == saved_nonce
user_id = claims["sub"]Read the profile
#With profile:read, GET /v1/account/profile returns the display name. email and email_verified are included only when the user granted email:read. /oauth/userinfo returns the same claims for tokens that include openid.
curl https://api.ozvault.lol/v1/account/profile -H "Authorization: Bearer ova_..."{
"sub": "q8ZtV1cLw0aJ3kP5rX7yNg",
"name": "Ada",
"email": "ada@example.com",
"email_verified": true
}Clear documentation is part of the product.