Authentication
Merion's API uses OpenID Connect (OIDC) with the authorisation code and PKCE flow. This is for approved integrators only — contact us to request access.
Overview
The Merion API uses OpenID Connect (OIDC) for authentication. The identity provider is at auth.merion.com.au. All authenticated API calls require a short-lived Bearer token obtained through the OIDC authorisation code flow with PKCE (S256).
PKCE (Proof Key for Code Exchange) prevents authorisation code interception attacks
without requiring a long-lived client secret. The S256 challenge method
(SHA-256) is required — plain PKCE is rejected.
Access is by arrangement. To request credentials, email [email protected] with the subject line "API Access Request". See Getting Started for what to include in your request.
Discovery document
Rather than hardcoding endpoint URLs, fetch the OIDC discovery document at startup and read the endpoint URLs from it:
GET https://auth.merion.com.au/.well-known/openid-configuration
The discovery document contains authorization_endpoint,
token_endpoint, userinfo_endpoint, jwks_uri,
and other configuration. See OIDC Discovery for the
full field reference.
Algorithm
All ID tokens are signed using ES256 — ECDSA with the P-256 curve and SHA-256.
The public signing keys are served at the jwks_uri in the discovery document.
Your OIDC library should verify the token signature automatically using those keys.
PKCE flow step by step
- Generate a
code_verifier. This is a cryptographically random string, 43–128 characters, URL-safe Base64 (charactersA-Z,a-z,0-9,-,_,.,~). Do not store it in browser storage accessible to JavaScript — use a server-side flow or a confidential client where the verifier is kept server-side. - Compute the
code_challenge.
Most OIDC libraries compute this for you when you specifycode_challenge = BASE64URL(SHA256(ASCII(code_verifier)))code_challenge_method=S256. - Redirect the user to the
authorization_endpointwith these query parameters:response_typecodeclient_id- Your assigned client ID
redirect_uri- Your registered callback URL
scopeopenid profilecode_challenge- The computed challenge (step 2)
code_challenge_methodS256state- A random, unguessable value — you will verify this on return
- User authenticates at
auth.merion.com.au. - Auth server redirects back to your
redirect_uriwithcodeandstatequery parameters. - Verify the
stateparameter matches the value you sent. Reject the response if it does not match — this is your CSRF protection. - Exchange the authorisation code for tokens. POST to the
token_endpoint(read from the discovery document):curl -s -X POST https://auth.merion.com.au/token \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=authorization_code" \ -d "code=<authorization_code>" \ -d "redirect_uri=<your_redirect_uri>" \ -d "client_id=<your_client_id>" \ -d "code_verifier=<your_code_verifier>"The
token_endpointURL shown above is illustrative — always read it from the discovery document, not hardcoded. - Receive the token response. A successful exchange returns:
access_token- Short-lived JWT; use as the Bearer token
id_token- Signed JWT with identity claims; validate before trusting
refresh_token- Long-lived; use to obtain new access tokens without re-authentication (if configured)
expires_in- Seconds until the access token expires; treat this value as authoritative
- Use the access token. Include it as a Bearer token on all authenticated API requests:
Authorization: Bearer <access_token>
Refreshing tokens
Access tokens are short-lived. Before the access token expires (use expires_in
to track expiry), use the refresh token to obtain a new access token:
curl -s -X POST <token_endpoint> \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "refresh_token=<your_refresh_token>" \
-d "client_id=<your_client_id>" Rotate refresh tokens on use — treat the refresh token from the response as the new one. Do not reuse refresh tokens across multiple concurrent requests.
Validating ID tokens
Validate the ID token before trusting any of its claims:
- Fetch the public keys from the
jwks_uriin the discovery document. - Verify the token signature using the key matching the
kidheader claim. - Verify the
issclaim equalshttps://auth.merion.com.au. - Verify the
audclaim equals yourclient_id. - Verify the
expclaim has not passed (token has not expired).
Most OIDC client libraries handle all of these checks automatically when you call their validation function. Do not skip validation in production code.
Requesting access
API access is by arrangement. Email [email protected] with the subject line "API Access Request". Include your use case, the integration you are building, and your relationship with Merion. Upon approval you will receive a client ID and onboarding steps.
Ready to integrate with Merion?
API access is available to approved partners and integrators. Contact us to start the conversation — no commitment required.