Skip to content
Developer guide

Sign in with EVORIV in your own app: OAuth with PKCE

An API key acts as one person. When every user of your app should work with their own EVORIV account and their own permissions, use Sign in with EVORIV: the OAuth authorization code flow with PKCE, as OAuth 2.1 asks for.

In short

A workspace admin registers your app under Settings, Developers, Own apps. You send the person to https://api.evoriv.com/oauth/authorize with a PKCE challenge (S256), they allow it, and you exchange the code at https://api.evoriv.com/oauth/token for an access token (one hour) and a refresh token that rotates on every use. The token is used exactly like an API key, as that person.

1. Register your app

A workspace admin registers it in EVORIV under Settings, Developers, Own apps.

  • Name: shown to people on the consent screen.
  • Redirect URIs: 1 to 10, matched exactly. https, or http://localhost, 127.0.0.1 or [::1] on any port while you develop.
  • With its own server (confidential): the app gets a client secret evaps_..., shown once and renewable. Without (public, for a native app or a CLI): PKCE only.
  • Scopes the app may ask for: read (always), write, and send (only with write). Scopes can't be changed later: register a new app for more.

The app gets a client id evapp_.... During this phase only members of the workspace that registered the app can allow it.

2. Send the person to EVORIV

Generate a random code_verifier, keep it with a random state, and send the SHA-256 of the verifier (base64url) as code_challenge. PKCE with S256 is required for every app. The person signs in, sees your app's name, the workspace and what it asks for, ticks what they allow and chooses Allow.

Authorization URL
https://api.evoriv.com/oauth/authorize
  ?response_type=code
  &client_id=evapp_...
  &redirect_uri=https://your-app.example/callback
  &scope=read%20write
  &state=<random, checked on return>
  &code_challenge=<BASE64URL(SHA-256(code_verifier))>
  &code_challenge_method=S256

3. Exchange the code, refresh and sign out

You get code (evmco_..., valid 60 seconds, once) and state at your redirect URI. Check state, then exchange the code with your verifier. A confidential app authenticates with HTTP Basic or client_secret in the body.

Node.js (Express)
// npm install express    (Node.js 18 or later)
import express from "express";
import { createHash, randomBytes } from "node:crypto";

const CLIENT_ID = process.env.EVORIV_CLIENT_ID;         // evapp_...
const CLIENT_SECRET = process.env.EVORIV_CLIENT_SECRET; // evaps_..., only for an app with its own server
const REDIRECT_URI = "http://localhost:3000/callback";  // registered exactly like this
const pending = new Map(); // state -> code_verifier; use your session store
const app = express();

app.get("/login", (req, res) => {
  const state = randomBytes(16).toString("base64url");
  const verifier = randomBytes(32).toString("base64url");
  const challenge = createHash("sha256").update(verifier).digest("base64url");
  pending.set(state, verifier);
  const url = new URL("https://api.evoriv.com/oauth/authorize");
  url.search = new URLSearchParams({
    response_type: "code", client_id: CLIENT_ID, redirect_uri: REDIRECT_URI,
    scope: "read write", state, code_challenge: challenge, code_challenge_method: "S256",
  }).toString();
  res.redirect(url.toString());
});

app.get("/callback", async (req, res) => {
  const verifier = pending.get(String(req.query.state));
  pending.delete(String(req.query.state));
  if (!verifier || !req.query.code) return res.status(400).send("Sign-in was cancelled or failed.");
  const tokens = await token({
    grant_type: "authorization_code", code: String(req.query.code),
    redirect_uri: REDIRECT_URI, code_verifier: verifier,
  });
  // Keep tokens on the server: access_token (1 hour), refresh_token (rotates), scope.
  res.send(`Signed in with scopes: ${tokens.scope}`);
});

async function token(params) {
  const body = new URLSearchParams({ ...params, client_id: CLIENT_ID });
  if (CLIENT_SECRET) body.set("client_secret", CLIENT_SECRET);
  const res = await fetch("https://api.evoriv.com/oauth/token", { method: "POST", body });
  const json = await res.json();
  if (!res.ok) throw new Error(json.error_description ?? json.error);
  return json; // { access_token, token_type: "Bearer", expires_in, refresh_token, scope }
}

// Before the hour is up: rotate. Store the NEW refresh token, forget the old one.
export const refresh = (refreshToken) => token({ grant_type: "refresh_token", refresh_token: refreshToken });

app.listen(3000);

4. Call the API as that person

The access token (evapi_...) works exactly like an API key, for one hour. Each request runs as the person: what they may see, the fields they may read and the changes they may make. Use it from your server, a native app or a CLI; a browser front end calls your own backend, because requests with an Origin header are refused.

curl
curl https://api.evoriv.com/api/dev/v1/record-types \
  -H "Authorization: Bearer $ACCESS_TOKEN"   # evapi_... from /oauth/token

# Sign out: end the whole authorisation with its refresh token
curl -X POST https://api.evoriv.com/oauth/revoke -d token=evapr_...

Scopes, rotation and revoking

  • What a token may do is what the app may ask for, what the person allowed and what the person may do in EVORIV, all three.
  • read: read what the person can see, and count and add up. write: add and change data where the person may. send: send a quote, an appointment confirmation or a signed work report on the person's behalf, each time after their confirmation in your app; only with write.
  • Refresh tokens (evapr_...) rotate on every use. Presenting a used one again revokes the whole authorisation, so store the new one before you use the access token.
  • The person revokes your app in EVORIV under My profile, AI assistants and apps. An admin can switch the app off, which stops all its tokens at once.
  • An app's token has the API-key limits per person and app, and 300 requests a minute per app in the workspace.

Questions about Sign in with EVORIV

Is this OAuth 2.0 or OAuth 2.1?
It is the OAuth 2.0 authorization code flow with PKCE required for every app and refresh token rotation, the way OAuth 2.1 asks for it. Discovery is at https://api.evoriv.com/.well-known/oauth-authorization-server.
Can people from other EVORIV workspaces sign in to my app?
Not yet. During this phase only members of the workspace that registered the app can allow it. Sharing apps with other EVORIV customers is planned for creators.
Do I need an API key as well?
No. The tokens from Sign in with EVORIV are Developer API tokens. Use an API key for a server integration that acts as one person, and Sign in with EVORIV when every user works as themselves.

Build it in a workspace of your own.

A development environment to build and test in, with demo data and every API endpoint.

Want to run your company on EVORIV? Start free