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
httpsaddress; 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 plainhttpis 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_codefor signing people in,refresh_tokenif the application should stay signed in for longer than an access token lives, andclient_credentialsonly for a machine scope. - A back-channel logout address (optional), an
httpsaddress 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.
Discovery
Section titled “Discovery”The discovery document is at:
https://api.nemar.org/.well-known/openid-configurationThe 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.
Endpoints
Section titled “Endpoints”| 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_challengewithcode_challenge_method=S256. Theplainmethod is refused. response_mode, if you send it, must bequery.- Send
stateandnonce; both come back,stateon the redirect andnoncein the identity token. Anoncemay be up to 512 characters. - The redirect back to you carries
code,stateandiss(Request for Comments (RFC) 9207). Checkiss. openidmust be among the scopes. A scope name outside the catalog is dropped without an error; a catalog scope your client was not registered for isinvalid_scope.requestandrequest_uriare not supported, and are answeredrequest_not_supportedandrequest_uri_not_supported.promptmay benone,login,consentorselect_account, andnonemay not be combined with another value. Withnone, NEMAR never shows a page: it redirects back withlogin_requiredorconsent_requiredif it needs the person. Withlogin, NEMAR asks the person to sign in again even if they are signed in.consentasks again even for a client that was already approved.max_age(whole seconds) asks for a sign-in no older than that. Theauth_timeclaim of the identity token says when the person last signed in, so check it rather than trust the request.id_token_hintis 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_localesandacr_valuesare accepted and have no effect. Any other unknown parameter is ignored. A parameter sent twice is answeredinvalid_request. The exception is a repeatedclient_idorredirect_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.
Scopes and claims
Section titled “Scopes and claims”| 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.
The sub claim and orcid_verified
Section titled “The sub claim and orcid_verified”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.
Tokens and their lifetimes
Section titled “Tokens and their lifetimes”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.
Verifying an identity token
Section titled “Verifying an identity token”The library you use will do most of this. If you check by hand, in this order:
- Read the
kidfrom the header and find that key in the key set atjwks_uri. If thekidis not in the set you cached, fetch the set again once before you refuse the token. - Verify the signature with
ES256as the only algorithm you accept. Refusenone, and refuse anything signed with another algorithm. - Check that
issishttps://api.nemar.org. - Check that
audis your client identifier. - Check that
exphas not passed, allowing a few seconds of clock skew. - Check that
nonceis the value you sent. - Check
at_hash: it is the left half of the SHA-256 hash of the access token, base64url-encoded. - Check
auth_timeif you asked formax_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.
Refresh rotation and the 30-second retry
Section titled “Refresh rotation and the 30-second retry”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 and introspection
Section titled “Revocation and introspection”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.
Back-channel logout
Section titled “Back-channel logout”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.iatandexp: 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 memberhttp://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:
- Verify the signature against the key set, accepting only
ES256. - Check that the header
typislogout+jwt, so an identity token cannot be passed off as a logout token. - Check
issandaud, and thatexphas not passed. - Check that
eventshas the back-channel logout member. - Check that there is no
nonce. - Check that you have not seen this
jtibefore.
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.
Errors
Section titled “Errors”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.
A worked example
Section titled “A worked example”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=S256The 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.orgCheck that state is yours and iss is the issuer, then redeem the code from your server:
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_VERIFIERThe 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:
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.