Skip to content

Sign in with NEMAR

NEMAR is an OpenID Connect (OIDC) provider. A web application that registers with NEMAR can sign people in with their NEMAR account, learn who they are, and be told when NEMAR ends their access. The protocol is the authorization code flow of the Open Authorization (OAuth) 2.0 framework, with identity tokens as OpenID Connect Core defines them. NEMAR itself signs people in with a one-time code sent by email, or with their Open Researcher and Contributor identifier (ORCID iD); a client never sees either, only the tokens and claims described here.

Any standard OIDC client library can do the whole flow from the discovery document. Read the endpoints and the signing keys from there, and hard-code neither.

Who this is for, and how a client is registered

Section titled “Who this is for, and how a client is registered”

This page is for the developers of an application that wants a “Sign in with NEMAR” button. It is a reference for the protocol; it is not a guide to NEMAR datasets, which are served by the public data host. A partner that launches compute jobs for NEMAR users also follows Compute partner integration.

There is no self-service registration. NEMAR registers each client by hand. To request one, write to support@nemar.org with:

  • A name for the application, which is what people see on the consent screen.
  • Redirect addresses, written out in full. Each is an https address; a client matches on the exact address, character for character, so there are no wildcards and no fragments. Up to ten may be registered. A loopback address with plain http is accepted only outside production, for development.
  • Scopes the application needs, from the scope table below. Ask for the least you need.
  • Grants the application needs: authorization_code for signing people in, refresh_token if the application should stay signed in for longer than an access token lives, and client_credentials only for a machine scope.
  • A back-channel logout address (optional), an https address NEMAR calls when an account’s access ends. In production it must be a named host, not a loopback address or a numeric Internet Protocol (IP) address. See back-channel logout.
  • A contact at the application who can be reached about an incident.

NEMAR also settles two things at registration. The first is who may sign in to the client: any active NEMAR account, or only a person whose ORCID iD was proven by signing in with ORCID. The second is whether the consent screen is shown. Every client that is not run by NEMAR itself is shown a consent screen, once per set of scopes by default or on every sign-in if you ask for that.

NEMAR gives you a client identifier and a client secret. The secret is shown once and NEMAR keeps only a hash of it, so store it at once, on your server, and never in a browser or a mobile application. A secret can be rotated; NEMAR keeps the previous one valid for an agreed grace period so you can deploy the new one without an outage.

The discovery document is at:

https://api.nemar.org/.well-known/openid-configuration

The issuer is exactly https://api.nemar.org, with no trailing slash. An identity token carries that value in its issuer claim, iss, and your library must compare it character for character.

The discovery document and the key set may be cached for up to 5 minutes (300 seconds), and are served even while the rest of the platform is in maintenance. The document lists the supported scopes and claims, so what you read there always matches what the provider does.

Endpoint Address Methods
Authorization https://app.nemar.org/oauth/authorize a browser navigation
Token https://api.nemar.org/oauth/token POST
Userinfo https://api.nemar.org/oauth/userinfo GET, POST
Key set (JavaScript Object Notation (JSON) Web Key Set, JWKS) https://api.nemar.org/oauth/jwks GET
Revocation https://api.nemar.org/oauth/revoke POST
Introspection https://api.nemar.org/oauth/introspect POST

The authorization endpoint is on the web application’s host, not that of the NEMAR application programming interface (API), because that is where people are signed in. Every other endpoint is on the issuer’s host. The token, revocation and introspection endpoints take an application/x-www-form-urlencoded body of at most 16 kilobytes with each parameter at most once, and every answer from them is marked Cache-Control: no-store.

Authorization code with Proof Key for Code Exchange (PKCE). This is the flow for signing a person in, and PKCE is required for every client.

  • Send response_type=code. There is no implicit flow and no password grant.
  • Send code_challenge with code_challenge_method=S256. The plain method is refused.
  • response_mode, if you send it, must be query.
  • Send state and nonce; both come back, state on the redirect and nonce in the identity token. A nonce may be up to 512 characters.
  • The redirect back to you carries code, state and iss (Request for Comments (RFC) 9207). Check iss.
  • openid must be among the scopes. A scope name outside the catalog is dropped without an error; a catalog scope your client was not registered for is invalid_scope.
  • request and request_uri are not supported, and are answered request_not_supported and request_uri_not_supported.
  • prompt may be none, login, consent or select_account, and none may not be combined with another value. With none, NEMAR never shows a page: it redirects back with login_required or consent_required if it needs the person. With login, NEMAR asks the person to sign in again even if they are signed in. consent asks again even for a client that was already approved.
  • max_age (whole seconds) asks for a sign-in no older than that. The auth_time claim of the identity token says when the person last signed in, so check it rather than trust the request.
  • id_token_hint is honored as a hint. If it is a valid identity token from NEMAR for a different account than the one signed in, NEMAR asks for a fresh sign-in.
  • login_hint, display, ui_locales, claims_locales and acr_values are accepted and have no effect. Any other unknown parameter is ignored. A parameter sent twice is answered invalid_request. The exception is a repeated client_id or redirect_uri: NEMAR shows its own error page and does not redirect, because it cannot then tell where to send the person.

The authorization code lives for 60 seconds and can be redeemed once. Redeem it at the token endpoint with the code_verifier you made. A code that is presented a second time is refused with invalid_grant, and every token that was issued from it is revoked, on the reading that a replayed code means it leaked.

Client authentication. A client authenticates to the token, revocation and introspection endpoints with Hypertext Transfer Protocol (HTTP) Basic: the client identifier and secret, each form-encoded, then joined with a colon and base64-encoded in the Authorization header (RFC 6749 section 2.3.1). This is the only method, and discovery says so (client_secret_basic). A secret sent in the request body is refused with invalid_client. A NEMAR command-line interface (CLI) key is not a client credential.

Client credentials. A client may be registered to use the client_credentials grant for a machine scope. It receives an access token for itself, with no account behind it, no identity token and no refresh token. A person can never consent to a machine scope.

Refresh token. See refresh rotation.

Scope Claims it adds Notes
openid sub Required.
profile name, given_name, family_name A part the person has not filled in is left out.
email email, email_verified
orcid orcid, orcid_verified Left out for an account with no ORCID iD.
nemar.account nemar_kind, nemar_status, nemar_tier The account’s kind, status and tier.
offline_access none Allows a refresh token.
compute.read none For NEMAR’s compute service; read through the API, not from a token.
compute.reserve none As compute.read.
compute.submit none As compute.read.
compute.stats none Machine only: granted under the client credentials grant, never to a person.

A claim with no value is omitted, never sent as null or as an empty string. The same claims are in the identity token and at the userinfo endpoint; both are read from the account at the moment of the call. orcid is the full address, https://orcid.org/ followed by the iD. nemar_kind is person, service or test. nemar_tier is base or upload, and is omitted for an account that has no tier.

sub is nmu_ followed by 32 lowercase hexadecimal characters. It identifies one NEMAR account, it is never reused, and it is a pseudonymous identifier: it exposes no email address and no ORCID iD. Key your accounts on the sub. Do not key them on email or orcid, which a person can change.

orcid_verified is true only when the person proved the iD by signing in with ORCID. An iD that an administrator attested, or that a publication filled in, does not count, and orcid_verified is false for it. If your application needs a proven iD, ask NEMAR to register the client so that only people with a proven iD may sign in, rather than checking the claim yourself.

ES256 is the Elliptic Curve Digital Signature Algorithm (ECDSA) over the P-256 curve with the Secure Hash Algorithm 256 (SHA-256) hash. It is the only signing algorithm NEMAR uses.

Token Lifetime Notes
Authorization code 60 seconds Single use.
Identity token (ID token) 5 minutes A JSON Web Token (JWT) signed with ES256, with a kid header.
Access token 15 minutes Opaque. The token response says expires_in of 900.
Refresh token 30 days idle, 90 days absolute Opaque. Rotated on every use.
Refresh retry window 30 seconds A used refresh token is still accepted this long.

Access tokens, refresh tokens and client secrets are opaque strings. Do not parse them, do not depend on their length or their characters, and do not log them. An access token is for the endpoints that serve its scopes, such as userinfo. It is not a NEMAR API key and the rest of the NEMAR API refuses it with the code oidc_token_not_accepted.

The token response carries access_token, token_type (Bearer), expires_in, scope, and, for the authorization code grant, an id_token, plus a refresh_token when the scope includes offline_access and the client may use the refresh grant. A refresh response carries an access token and a new refresh token, and no identity token.

The library you use will do most of this. If you check by hand, in this order:

  1. Read the kid from the header and find that key in the key set at jwks_uri. If the kid is not in the set you cached, fetch the set again once before you refuse the token.
  2. Verify the signature with ES256 as the only algorithm you accept. Refuse none, and refuse anything signed with another algorithm.
  3. Check that iss is https://api.nemar.org.
  4. Check that aud is your client identifier.
  5. Check that exp has not passed, allowing a few seconds of clock skew.
  6. Check that nonce is the value you sent.
  7. Check at_hash: it is the left half of the SHA-256 hash of the access token, base64url-encoded.
  8. Check auth_time if you asked for max_age.

The key set changes by rotation, which is announced in the set itself. Normally a new key appears in the set at least 24 hours before it signs anything. An emergency rotation can use a key that was published only minutes earlier, so a client that sees a kid it does not know should fetch the key set again. A retired key stays in the set for up to 7 days after it stops signing, so a token signed just before a rotation still verifies; NEMAR can withdraw a retired key sooner if it must, and publishes at most 5 retired keys. Cache the key set for no more than the 5 minutes the response allows.

Every use of a refresh token returns a new one and spends the old one. Store the new refresh token before you use the new access token.

A network failure can leave you not knowing whether NEMAR saw your request. For that case a refresh token that has just been used is still accepted for 30 seconds: present the same token again and you receive a fresh pair. The two refresh tokens that came from the one parent exclude each other, so use only one of them; as soon as one is used, the other is revoked.

After the 30 seconds, presenting a used refresh token again is treated as reuse, because it means a copy of the token exists somewhere it should not. NEMAR then revokes the whole family of tokens, and the answer is invalid_grant. The same answer follows a refresh token that has expired or been revoked. When you receive invalid_grant for a refresh token, discard the tokens and send the person to sign in again. A scope parameter on a refresh request can only narrow the scopes; anything wider is invalid_scope.

Revocation (RFC 7009). Authenticate as the client and POST a form with the token. NEMAR answers 200 whatever the token was, including one it does not know or that belongs to another client. Revoking a refresh token ends its whole family, access tokens included. Revoking an access token ends only that token.

Introspection (RFC 7662). Authenticate as the client and POST a form with the token. The answer is {"active": false} and nothing else unless the token is active now and the caller may be told. A caller may be told about its own tokens, and about the access tokens issued for an audience that NEMAR registered it to introspect. For an active token the answer holds active, scope, client_id, token_type (access tokens only), exp, iat, sub (when an account is behind the token), aud and iss. Introspection reads the live state: a token whose account was revoked a moment ago is inactive, whatever its exp says.

When NEMAR ends a person’s access, it can tell your application, using OpenID Connect Back-Channel Logout 1.0. Register a back-channel logout address to receive these calls.

When NEMAR sends it. When an account is revoked, deleted, or merged into another, and only to a client that holds a live grant for that account and has a registered logout address. For a client that only admits people with a proven ORCID iD, it is also sent when the person unlinks or replaces the iD, and when the account stops being a person’s.

The request. NEMAR sends a POST of one form field, logout_token, to your registered https address. There are no credentials, no cookies and no other field. NEMAR waits 5 seconds for the answer and never follows a redirect, so the address must answer directly. Reply 200 or 204.

The token. The logout token is a JWT signed with ES256 under a key from the same key set as identity tokens. Its header has typ set to logout+jwt. Its claims are:

  • iss: the issuer.
  • aud: your client identifier.
  • iat and exp: the issue time, and the expiry two minutes later.
  • jti: a new unique value for every attempt.
  • sub: the account whose access ended.
  • events: an object with the member http://schemas.openid.net/event/backchannel-logout.

There is no nonce, and no sid: NEMAR does not keep a session identifier for you, so end every session your application holds for that sub.

What a verifier checks. Before acting on a logout token:

  1. Verify the signature against the key set, accepting only ES256.
  2. Check that the header typ is logout+jwt, so an identity token cannot be passed off as a logout token.
  3. Check iss and aud, and that exp has not passed.
  4. Check that events has the back-channel logout member.
  5. Check that there is no nonce.
  6. Check that you have not seen this jti before.

Answer 400 for a token you refuse; that stops NEMAR retrying it.

Retries. An answer of 5xx, 408 or 429, a timeout and a failed connection are retried, at 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours after the previous attempt, six attempts in all. Each retry is a new token with a new jti. A Retry-After header on a 408 or 429 can only lengthen a wait, up to 12 hours, and cannot add an attempt. Retries run on a half-hourly schedule, so a short wait is taken up at the next half hour. The six attempts span about 15 to 18 hours on the schedule alone, and up to about 63 hours when a throttling partner asks for the longest wait every time. Any other 4xx, a redirect, or any other answer is not retried.

After the sixth attempt NEMAR stops. A client that must be certain a person’s access has ended therefore also checks introspection or userinfo, both of which refuse an ended grant at once. Treat a logout token as a prompt to act early, not as the only way your application learns that access has ended.

Authorization errors are returned by redirecting to your registered address, with error, your state and iss in the query:

Error Meaning
invalid_request The request is malformed: a missing response type, a repeated parameter other than client_id and redirect_uri, no PKCE challenge or a method other than S256, a response mode other than query, or an unreadable prompt, max_age or nonce.
unsupported_response_type The response type is not code.
invalid_scope openid is missing, or a scope is one your client may not have, or is machine only.
request_not_supported A request parameter was sent.
request_uri_not_supported A request_uri parameter was sent.
login_required prompt=none, and the person is not signed in or must sign in again.
consent_required prompt=none, and the person has not approved this client for these scopes.
access_denied The person refused on the consent screen, or the account may not sign in to this client.

When the client is unknown or disabled, or the redirect address is not exactly one you registered, NEMAR does not redirect. It shows its own page, because it cannot trust the request to say where to send the person.

Token endpoint errors are a JSON body of error and error_description, with status 400; invalid_client is 401 with a WWW-Authenticate: Basic challenge. The description is a fixed sentence and never repeats what you sent.

Error Meaning
invalid_request A required parameter is missing, the body is not a well-formed form, or a parameter is repeated.
invalid_client The client could not be authenticated.
invalid_grant The code, the verifier, the redirect address or the refresh token is not valid for this request, or the account no longer qualifies.
unauthorized_client The client may not use that grant type.
unsupported_grant_type NEMAR does not offer that grant type.
invalid_scope The scope asked for is not within what was granted.

Userinfo errors follow RFC 6750. With no Authorization header the answer is 401 with a bare WWW-Authenticate: Bearer challenge. With a token that is not a live access token it is 401 with error="invalid_token". With a live token that lacks the openid scope it is 403 with error="insufficient_scope". A token is read live, so it stops working the moment its grant or its account ends.

On any other NEMAR route, an access token is answered 401 with the code oidc_token_not_accepted.

This uses a placeholder client at client.example.org registered with the redirect address https://client.example.org/callback.

Generate a code_verifier (43 to 128 characters from A-Z a-z 0-9 - . _ ~), and its challenge, which is the base64url encoding of the SHA-256 hash of the verifier. Send the person to:

https://app.nemar.org/oauth/authorize
?response_type=code
&client_id=YOUR_CLIENT_ID
&redirect_uri=https%3A%2F%2Fclient.example.org%2Fcallback
&scope=openid%20profile%20orcid
&state=RANDOM_STATE
&nonce=RANDOM_NONCE
&code_challenge=CODE_CHALLENGE
&code_challenge_method=S256

The person signs in if they are not signed in, approves the consent screen, and is sent to:

https://client.example.org/callback?code=THE_CODE&state=RANDOM_STATE&iss=https%3A%2F%2Fapi.nemar.org

Check that state is yours and iss is the issuer, then redeem the code from your server:

Terminal window
curl -s https://api.nemar.org/oauth/token \
-u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
-d grant_type=authorization_code \
-d code=THE_CODE \
-d redirect_uri=https://client.example.org/callback \
-d code_verifier=YOUR_CODE_VERIFIER

The answer carries the tokens:

{
"access_token": "...",
"token_type": "Bearer",
"expires_in": 900,
"scope": "openid orcid profile",
"id_token": "..."
}

Verify the identity token as described above, and key the person on its sub. To read the claims again later, call userinfo while the access token is live:

Terminal window
curl -s https://api.nemar.org/oauth/userinfo -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Most OIDC client libraries do all of this from the issuer address alone: give the library https://api.nemar.org, your client identifier and secret, the redirect address and the scopes, and let it fetch the discovery document.