Skip to main content
Developer

Client assertion#

View as Markdown
On this page

A client assertion is a JSON Web Token (JWT) that the API client signs with its own private key (private_key_jwt, RFC 7523⁠ (opens in a new tab)). This guide shows how to set up client assertions, so that the API client can get access tokens from the ID Check authorisation server.

Prerequisites#

  • An API client, with the client ID from Stø. See Get access.
  • A JSON Object Signing and Encryption (JOSE) or JWT library that can sign a JWT with one of the algorithms in step 1.

1. Create a key pair#

Create the key pair on the merchant's own systems, and keep the private key secret. The authorisation server supports these algorithms:

AlgorithmKey
ES256An EC key on the P-256 curve
PS256 or RS256An RSA key of at least 2048 bits
Ed25519An OKP key on the Ed25519 curve

2. Register the public key#

The authorisation server uses the public key to verify the signature of each client assertion. Give Stø the public key in one of these forms:

  • A public JSON Web Key (JWK) (RFC 7517⁠ (opens in a new tab)). Send it to Stø, as Support describes. Stø enrols it for the API client.
  • The URL of a JSON Web Key Set (JWKS). Publish the public keys as a JWKS at an https URL that the merchant controls, and send the URL to Stø. The URL must use the default port, 443. It must return the JWKS with status 200, without a redirect. When Stø sets up the JWKS URL, it allows the host of the URL in the ID Check firewall. After that, the merchant can add and remove keys without contacting Stø.

Never send the private key to Stø.

Give each key a kid. If a key has an alg member, it must be the algorithm that the API client signs with. If a key has a use member, it must be sig.

The authorisation server caches the JWKS for 5 minutes. When a client assertion names a key that is not in the cached JWKS, the authorisation server fetches the JWKS again, but not within 30 seconds of the last fetch. If it cannot fetch the JWKS, the token request fails. It tries to fetch the JWKS again on the next token request.

3. Create a client assertion#

The JWT has these header parameters and claims. Send each one that the table does not mark as optional:

MemberValue
algES256, PS256, RS256 or Ed25519. For an Ed25519 key, use Ed25519, not EdDSA.
kidThe kid of the key. Always send it, so that the authorisation server can find the key when there is more than one.
typOptional. client-authentication+jwt (recommended) or JWT.
issThe client ID.
subThe client ID.
audThe issuer in the authorisation server metadata, as a single string. In production, this is https://prod.idcheck.bankid.no.
expThe expiry time. Not more than 60 seconds in the future.
iatOptional. The time of issue. Not in the future, and not more than 60 seconds in the past.
nbfOptional. If present, it must not be in the future.
jtiA unique ID, for example a random UUID.

Each client assertion is valid for one use only. Create a new client assertion, with a new jti, for each token request. Do this also for a retry after a failure. A second request with the same client assertion fails, also before the client assertion expires.

4. Request a token#

Send the client assertion in the request body:

POST /oauth/token HTTP/1.1
Host: auth.prod.idcheck.bankid.no
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer&client_assertion=<<CLIENT_ASSERTION>>&scope=handover:create+handover:read

The client_id parameter is optional. If present, it must be the same as the iss and the sub of the client assertion.

The scope parameter gives the scopes.

The response contains the access token. See Authentication.

Rotate keys#

To replace a key without failed token requests:

  1. 1

    Add the new key. Give it a new kid. With a JWKS URL, publish the new key next to the old key, and wait at least 30 seconds. With a public JWK, send the new key to Stø, and wait until Stø confirms that it enrolled the key.

  2. 2

    Sign with the new key. Put the new kid in the header of each client assertion.

  3. 3

    Remove the old key. With a JWKS URL, remove the old key from the JWKS. The authorisation server can still accept the old key for up to 5 minutes. With a public JWK, ask Stø to remove the old key.

Test the integration#

Stø gives access to the preproduction environment of ID Check for tests. Stø gives the preproduction details during the set-up of access. Preproduction has its own host names, so its token endpoint and its aud value are different. Register a public key for preproduction too, as in step 2.

  1. 1

    Request a token in preproduction. The response has status 200 and an access_token.

  2. 2

    Create a session. Use the access token to create a session in preproduction.

  3. 3

    Fetch the session. Use the access token to fetch the session in preproduction.

Next steps#

Was this page helpful?