Test mode: paid plans aren't on sale yet, so nothing is charged. Every plan's limits apply.

← Docs

APIs and services

Protecting your API

Register the API in the realm with the scopes it understands:

nod api register acme https://api.example.com --scope orders:read --scope orders:write --ttl 900

Your API accepts Nod access tokens for it, and checks each one:

  1. **It's a JWT with header typ: at+jwt** (RFC 9068). Refuse anything else, ID tokens included.
  2. The signature verifies with the key named by kid in <issuer>/jwks. Fetch the key set, cache it by kid, and refetch (rate-limited) when you meet an unknown kid. **Use the key's algorithm (EdDSA, or RS256 for an API set to token_alg: RS256), never the header's choice,** and never accept alg: none or HMAC.
  3. **iss is the realm's issuer, exactly. aud is your API's identifier. exp** has not passed.
  4. **scope** (space-separated) contains what the operation needs.

Most JWT libraries do steps 1–3 if you pin the algorithm, issuer and audience. Alternatively, a confidential client can ask Nod with POST <issuer>/introspect (RFC 7662), which answers {"active": false} for anything not active.

People calling APIs (roles)

An app that signs people in can ask for a token for an API by adding resource=<API identifier> to the authorization request, and the API's scopes to scope:

/authorize?…&scope=openid orders:read orders:write&resource=https://api.example.com

What the token carries comes from roles:

nod role create acme clerk --description "reads orders"
nod role grant acme clerk https://api.example.com --scope orders:read
nod user role acme alice clerk                 # --remove to take it away

The access token's aud is the API and the issuer, so userinfo still works. Its scope holds the requested API scopes the person's roles allow, and its permissions claim lists everything they hold there, as Auth0's RBAC does. Roles are read again at every refresh, so removing a role takes effect at the next one. The management API manages roles too (roles:read, roles:write).

Roles by email domain, and a role on everything

A realm can give a role to everyone who proved an address at a domain, and a role can allow every scope of every API, those registered later included. Both are read at each token and refresh, and neither is listed as assigned:

nod role grant lunaor staff --all                  # --remove to stop; the CLI and config files only
nod realm set lunaor --domain-roles lunaor.com=staff  # "" none; through the API, a nod

An address an administrator marked verified, an unverified one, a subdomain or a lookalike domain gives nothing. roles:write can't set --all, as it can't give permissions on the management API.

Email in access tokens

An API that grants by email (a team drive shared with alice@acme.example, or with everyone at acme.example) can read the person's address straight from its access token instead of calling userinfo:

nod api register acme https://drive.example.com --scope files:read --token-email

Its tokens then carry email and email_verified (RFC 9068's identity claims), when the person has an email and the app asked for the email scope. email_verified is true only for an address Nod verified, or one a federated connection (a Google company account, say) vouched for in a domain listed on that connection. Count an email only when it's true. The admin API and configuration files call the setting token_email. ID tokens and other APIs' tokens don't change.

The person's org in access tokens (nod_account)

An API that serves orgs can read which org the caller is acting in from its access token. Turn it on per API (off by default):

nod api set acme https://chat.example --claim nod_account     # `api set acme https://chat.example` turns it off

(Admin API and configuration files: "claims": ["nod_account"] on the API.) Its tokens then carry nod_account, an org's account id (acct-…), as a string:

Several APIs, one sign-in

An app that calls several APIs asks for all of them at once, repeating resource (RFC 8707), and then gets one token per API, each good only there:

/authorize?…&scope=openid offline_access orders:read billing:read
          &resource=https://orders.example&resource=https://billing.example

POST /token  grant_type=refresh_token&refresh_token=…&resource=https://billing.example

Services calling APIs (client credentials)

nod client register acme billing-service --machine                      # prints the secret once
nod client grant acme billing-service https://api.example.com --scope orders:read
curl -u billing-service:$SECRET https://auth.example.com/acme/token \
  -d grant_type=client_credentials -d resource=https://api.example.com [-d scope=orders:read]

With a key instead of a secret (private_key_jwt)

A service can prove who it is with its own private key, so no shared secret exists: nothing to leak from Nod, and nothing to copy between machines. Register the client with its public keys (a JWKS; never the private part):

nod client register acme deployer --machine --jwks deployer.jwks.json    # no secret is made

or through the management API, POST /api/v1/clients with "token_endpoint_auth_method": "private_key_jwt" and "jwks": {"keys": [...]}. To get a token, the service signs a short JWT with its key (ES256, EdDSA or RS256, kid naming the key) and sends it instead of a secret:

iss, sub   the client's id
aud        the realm's issuer, as the only value: https://auth.example.com/acme  (not the token endpoint)
exp        at most five minutes ahead
jti        unique: each assertion works once
typ        (header, optional) client-authentication+jwt
curl https://auth.example.com/acme/token -d grant_type=client_credentials -d resource=https://api.example.com \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer -d client_assertion=$JWT

Coming from Auth0? Auth0 wants the token endpoint (https://<tenant>/oauth/token) in aud; Nod refuses it and wants the issuer instead (the error says which). Libraries that default to the token endpoint usually take an audience option. Most OAuth libraries do this for you given the private key (openid-client: PrivateKeyJwt(key)). The audience rule is RFC 10070's fix for audience injection: Nod refuses an assertion naming its token endpoint, or naming anything besides its issuer. A client authenticates one way only: a key client can't use a secret, and a secret client can't switch to a key.

With a TLS client certificate (mTLS, RFC 8705)

A service can also authenticate with a TLS client certificate, for FAPI-style deployments. Its access tokens are then bound to that certificate (cnf.x5t#S256), so a stolen token is useless without the private key. Register the client with its certificates as a JWKS whose keys carry them in x5c (base64 DER):

nod client register acme payments --machine --jwks payments-certs.jwks.json --tls

or "token_endpoint_auth_method": "self_signed_tls_client_auth" with jwks over the management API.

Nod doesn't terminate the client's TLS itself: the proxy in front of it does. The proxy asks for a client certificate, accepts the client's own (self-signed is fine; the thumbprint is what's registered), and passes it on in the Client-Cert header (RFC 9440: Client-Cert: :<base64 DER>:). Nod believes that header only from the addresses in --trusted-proxies. From anyone else it's removed before any handler sees it. An API that accepts these tokens checks that the certificate on its own TLS connection has the thumbprint in cnf.x5t#S256. Userinfo does that check itself.

A client authenticates one way only: with its certificate, no secret or assertion, and its tokens aren't also DPoP-bound.

APIs calling APIs for a person (token exchange)

The orders API, handling Alice's request, needs to call the billing API as Alice. It exchanges her token for one to billing (RFC 8693), in her name:

nod client register acme orders-svc --machine
nod client grant acme orders-svc https://billing.example --scope billing:read --scope billing:write
nod client exchange acme orders-svc --from https://orders.example
curl -u orders-svc:$SECRET $ISSUER/token -d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
  -d subject_token=$ALICES_TOKEN -d subject_token_type=urn:ietf:params:oauth:token-type:access_token \
  -d resource=https://billing.example

Scopes only on a person's behalf

A grant is also what the service can get for itself with client credentials. When it should write only for a person, never alone, mark those scopes on-behalf-only:

nod client grant acme orders-svc https://billing.example --scope billing:read --on-behalf-only billing:write

(--on-behalf-only S grants S too; through the management API, PUT /clients/{id}/grants with {"resource", "scopes", "on_behalf_only"}, each of on_behalf_only one of scopes.)

Scope patterns

An API whose scopes name things created all the time can define patterns: * stands for one whole segment between colons, and a dotted prefix ending a segment (nod.*, a.b.*) stands for any dotted name under that prefix, at any depth (nod.acme, nod.acme.deploys; never nod itself or nodx). Sendack's topic scopes use it: sendack:topic:nod.*:publish.

nod api register acme https://twilightdb.example --scope 'twilightdb:db:*:read' --scope 'twilightdb:db:*:write'
nod client grant acme app https://twilightdb.example --scope twilightdb:db:orders:read      # one database
nod client grant acme ops https://twilightdb.example --scope 'twilightdb:db:*:read'        # any (operator)