How-to › Authenticate and authorize calls

How to choose a hosted or self-built authorization server#

Score Auth0, Cognito, Keycloak, Ory Hydra, and node-oidc-provider from quoted vendor pages, then run the OAuth flows against the front runner.

Audience
Platform team
Level
beginner
Topic
Design an authentication scheme for your API
Verified

You picked an authorization server on the size of its free tier, wired three apps to it, and shipped. The first agent integration requests a client credentials token on every call, and the bill counts tokens rather than users. Moving the clients to another server means re-registering each one and changing every issuer URL they trust.

What you get

You will end up with a scoring sheet in which every score rests on a quote from the vendor’s own page. A spike then runs the flows you need against a local server. This is for you if your API has no authorization server yet.

Short answer

Score each candidate on machine-to-machine token pricing, user pricing, RFC 7591 registration, who runs it, data residency, custom claims, and exit cost. Put a vendor quote behind every score, and one rule for all. Compare the totals under equal and under your own weights. Then spike the leader: run client credentials, authorization code with PKCE, and a refresh against it, and change a scope to see when tokens carry it.

You will need

Node 22 or later for the sample. A list of the clients your API must serve, which flows each one uses, and an estimate of machine token requests per month. The prices below are quoted from each vendor’s pricing page on the day of the last verification, so read the pages again before you sign anything.

Approaches compared

ApproachWhen it fitsWhat it costs youWhen to pick something else
Amazon CognitoYou run on AWS and stay inside the Lite or Essentials free tier of 10,000 monthly active usersEvery client credentials token request is billed, with no free tier for machine-to-machine useMachine clients outnumber people, or clients must register themselves
Auth0Up to 25,000 monthly active users free, and third-party clients that register themselvesMachine-to-machine authentication listed at 1,000 on Free, with an add-on only on Professional and EnterpriseAgent traffic will dwarf the machine-to-machine figure on your plan
KeycloakA team that can run a Java service, its database, and its upgradesYou run, patch, and back up the server and its database, with nobody else on callNobody will hold the pager for the identity tier
node-oidc-providerYou need your exact scheme, in Node, and accept writing login and consentLogin pages, storage, key rotation, and every security patch are your code from then onYou want an administration console and user accounts included
Ory HydraYou already have user accounts and want only the OAuth server, self-hosted or on Ory NetworkYou supply the login and consent app, and Ory Network prices each machine tokenYou want user accounts and login pages in the same product

The two hosted services remove the on-call rota and the security patching, and meter the traffic in exchange. Cognito’s pricing page says there is no free tier for token requests in the machine-to-machine case.1 The Auth0 pricing page lists 1,000 for machine-to-machine authentication on its Free plan. The three open source servers charge nothing per token, so the cost moves to your team. Keycloak brings user management, and node-oidc-provider is a library you assemble. Ory describes its OAuth 2.0 service as a headless API that doesn’t force you to use a specific user management system.

Put a quote behind every score

The sheet is a JSON file. Each score is 0, 1, or 2 under one rule per criterion, and carries the sentence it rests on and the page that says it. A 0 that rests on an absence names the pages searched and a control page where the same term is found.

      "name": "Auth0",
      "scores": {
        "m2m": { "score": 1, "url": "https://auth0.com/pricing", "quote": "Machine-to-Machine Authentication 1,000 1,000 5,000 5,000 M2M Add-on No No Yes Yes" },
        "users": { "score": 1, "url": "https://auth0.com/pricing", "quote": "Up to 25,000 monthly active users" },
        "dcr": { "score": 2, "url": "https://auth0.com/docs/get-started/applications/dynamic-client-registration", "quote": "Dynamic Client Registration (DCR) is based on the OpenID Connect Dynamic Client Registration specification" },
        "operations": { "score": 2, "url": "https://auth0.com/pricing", "quote": "over our standard public cloud offering" },
        "exit": { "score": 1, "url": "https://auth0.com/pricing", "quote": "With it, you can export all data to any format" },
        "residency": null,
        "claims": null
      }

record.sh downloads every cited page and checks each quote, each search, and each control against it. Its 35 checks passed. Data residency and custom claims are null: those depend on the region and the plan you would buy, so you fill them in. The scorer leaves a criterion out of the totals until every candidate has a score for it.

node score.mjs
                    M2M tokens users      RFC 7591   on-call    exit       residency  claims
Amazon Cognito      0          1          0          2          0          -          -
Auth0               1          1          2          2          1          -          -
Keycloak            2          2          2          0          2          -          -
Ory Hydra           2          2          2          0          2          -          -
node-oidc-provider  2          2          2          0          2          -          -

scored on: M2M tokens, users, RFC 7591, on-call, exit
still to score: residency, claims
weights: M2M tokens 3, users 1, RFC 7591 2, on-call 2, exit 1

equal weights            given weights
Keycloak 8               Keycloak 14
Ory Hydra 8              Ory Hydra 14
node-oidc-provider 8     node-oidc-provider 14
Auth0 7                  Auth0 13
Amazon Cognito 3         Amazon Cognito 5

The three open source servers tie because the sheet counts what they cost you on one row, on-call, and what they save on four. Raise the on-call weight in weights.json from 2 to 3 and Auth0 leads. Cognito scores 0 on registration because the three Cognito pages searched never mention it, not because a page says it is absent. Its 0 on exit rests the same way on two pages without the word “export.”

Spike the front runner on your own machine

The spike stands up node-oidc-provider on 127.0.0.1 with the features the plan needs. Login and consent are automatic for one test user, which stands in for the pages a deployment draws.

    features: {
      devInteractions: { enabled: false },
      clientCredentials: { enabled: true },
      registration: { enabled: true, initialAccessToken },
      registrationManagement: { enabled: true, rotateRegistrationAccessToken: false },

The script registers a client under RFC 7591, runs client credentials, runs authorization code with PKCE and a refresh, and then widens the client’s scope through the RFC 7592 update endpoint.2

node spike.mjs
dynamic registration (RFC 7591)              201, client_secret issued: true
client credentials                           200, scope "orders:read", aud the API
client credentials, scope not registered     400 invalid_scope
authorization code with PKCE                 200, scope "orders:read", refresh token: true
refresh                                      200, scope "orders:read", rotated: true
scope change (RFC 7592 update)               200
next client credentials token                200, scope "orders:read orders:write"
token issued before the change               scope "orders:read", lives 600 s

A scope change reaches the next token at once. A token issued before it keeps the earlier scope until it expires, after the 600 seconds this server is configured for.

record.sh ran the same plan against Ory Hydra 2.3.0, downloaded from its release page and checked against the release’s SHA-256. The functions in flows.mjs take Hydra’s endpoint paths, and a short stand-in accepts its login and consent requests:

cat records/hydra-spike.txt
dynamic registration (RFC 7591)              201, client_secret issued: true
client credentials                           200, scope "orders:read"
client credentials, scope not registered     400 invalid_scope
authorization code with PKCE                 200, scope "openid offline_access orders:read", refresh token: true
refresh                                      200, scope "openid offline_access orders:read", rotated: true
scope change (RFC 7592 update)               200
next client credentials token                200, scope "orders:read orders:write"
token issued before the change               scope "orders:read", lives 10 min

Hydra gave the same answers. On a hosted candidate, run the same flows against its free tier and record how long a change made in its dashboard takes to show up in a fresh token.

Check it worked

The suite pins the sheet’s rules and every flow in the spike, including a public client refused for leaving out PKCE, a wrong code verifier refused, and a reused refresh token refused.

node --test spike.test.mjs
1..14
# tests 14
# suites 0
# pass 14
# fail 0
# cancelled 0
# skipped 0
# todo 0

When it goes wrong

The bill jumps the month an agent integration ships. Its client requests a client credentials token per call, and the plan prices tokens. The arithmetic uses the price Ory Network’s pricing page gives for its Production plan, read from the quote record.sh checked:

node meter.mjs
4 agent instances, a 30-day month, Ory Network Production at $0.007 a token
token policy                              tokens        cost
a token per call, one call a second     10368000   $72576.00
a token every 5 minutes                    34560     $241.92
one token per 1 hour lifetime               2880      $20.16
usage at that price, before the $21.00 monthly credit the plan includes

Cache the token until it nears expiry, as cachedToken in flows.mjs does. The suite shows ten concurrent calls sharing one token request, against ten requests without the cache.

The scores stop matching the pages. Vendors change plans without notice, so run record.sh again before a decision meeting; a failed quote check exits non-zero.

When not to do this

Do not score on the free tier alone. A free tier sized for people says nothing about the tokens your machine clients will request.

Do not self-build because the sheet says it is free. node-oidc-provider gives you the exact scheme you designed and a codebase you must patch for as long as it runs. Choose Auth0 or Cognito when nobody on the team can own that.

Do not skip the spike because the documentation lists the feature. Run the three flows and the scope change against a free tier or a local copy. What a scope change does to tokens already issued depends on each server’s token lifetime and format.

Last verified

Verified 2026-11-30 against Node 22.23.5, oidc-provider 9.15.1, jose 6.2.18, and Ory Hydra 2.3.0, which record.sh ran. Every output block is what the command preceding it printed. Auth0, Amazon Cognito, Ory Network, and Keycloak were not run. Their scores and prices come from the pages listed in candidates.json, fetched and checked by record.sh on the same day.

Footnotes

  1. The same pricing page says the user free tier does not automatically expire at the end of the 12-month AWS Free Tier term, and is available indefinitely. On the Lite and Essentials tiers, ten thousand people a month who sign in directly or through a social provider cost nothing for as long as the account exists. A machine pays from its first token request. ↩︎ Back to text

  2. Both documents date from July 2015. RFC 7591 is on the Standards Track and covers creating a registration. RFC 7592, which covers reading, updating, and deleting one, is filed as Experimental, so the half of the spike that changes a scope rests on the experimental half of the pair. ↩︎ Back to text

Read this page as markdown · All how-to guides

Generate the client instead of writing it#

Retries, timeouts, pagination and auth are the same problems in every client. Voxgig generates them from your OpenAPI description, in 23 languages, from one model.

Listen to Fireside, the Voxgig podcast

Since 2018, Richard Rodger has talked with developer advocates, event organizers, and the people who build developer-facing companies about the specifics of the work.