Exchange the authorization code
#POST to /oauth/token from your server with grant_type=authorization_code, the code, the same redirect_uri and your code_verifier. Confidential clients authenticate with HTTP Basic (client_secret_basic) or client_id and client_secret in the body (client_secret_post). Public clients send client_id only.
Codes expire after two minutes and work once. Presenting a code twice revokes every token issued from it. Requests that carry a browser Origin header are refused for confidential clients, so a leaked secret cannot be used from a web page.
curl -X POST https://ozvault.lol/oauth/token \
-u "$OZVAULT_CLIENT_ID:$OZVAULT_CLIENT_SECRET" \
-d grant_type=authorization_code \
-d code=AUTHORIZATION_CODE_FROM_CALLBACK \
--data-urlencode "redirect_uri=https://example.com/auth/ozvault/callback" \
-d code_verifier=THE_VERIFIER_YOU_STOREDHTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token": "ova_3qHf...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "profile:read storage:app:read storage:app:write offline_access",
"refresh_token": "ovr_Q1mZ..."
}Token lifetimes
#Access tokens (ova_…) last one hour; expires_in is in seconds. Refresh tokens (ovr_…) are issued only when the user granted offline_access and last 30 days from their last use. OzVault stores only hashes of codes and tokens.
Refresh and rotation
#POST grant_type=refresh_token with the refresh token. Every refresh returns a new access token and a new refresh token; save both and discard the old refresh token. You may narrow scope with the scope parameter, but never widen it.
Rotation has replay detection: if an already-used refresh token is presented again, OzVault assumes it was stolen and revokes the entire session, and the user must authorize again. Make sure only one refresh per connection runs at a time.
// Serialize refreshes per connection: presenting an already-rotated
// refresh token is treated as theft and revokes the whole session.
const inFlight = new Map();
export function refreshTokens(connectionId, refreshToken) {
if (!inFlight.has(connectionId)) {
const request = fetch("https://ozvault.lol/oauth/token", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: "Basic " + Buffer.from(process.env.OZVAULT_CLIENT_ID + ":" + process.env.OZVAULT_CLIENT_SECRET).toString("base64"),
},
body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: refreshToken }),
})
.then(async (r) => {
const body = await r.json();
if (!r.ok) throw Object.assign(new Error(body.error_description), { code: body.error });
return { ...body, expiresAt: Date.now() + body.expires_in * 1000 }; // save ALL of it, including the new refresh_token
})
.finally(() => inFlight.delete(connectionId));
inFlight.set(connectionId, request);
}
return inFlight.get(connectionId);
}r = httpx.post("https://ozvault.lol/oauth/token", auth=(CLIENT_ID, CLIENT_SECRET),
data={"grant_type": "refresh_token", "refresh_token": tokens["refresh_token"]})
if r.status_code == 400 and r.json()["error"] == "invalid_grant":
... # the user disconnected your app or the session was revoked: ask them to connect again
tokens = r.json() # store the NEW refresh_tokenIntrospection for resource servers
#If a separate service of yours receives OzVault access tokens, it can ask /oauth/introspect whether a token is active (RFC 7662). Authenticate as your client; tokens issued to other clients always report active:false.
curl -X POST https://ozvault.lol/oauth/introspect -u "$OZVAULT_CLIENT_ID:$OZVAULT_CLIENT_SECRET" -d token=ova_...
{"active":true,"scope":"profile:read storage:app:read","client_id":"ovc_...","token_type":"access_token","exp":1791734400,"iat":1791730800,"sub":"q8Zt...","aud":"ovc_...","iss":"https://ozvault.lol"}Clear documentation is part of the product.