Authentication#
On this page
The token endpoint of the ID Check authorisation server gives the API client an access token for the Handover API.
POST https://auth.prod.idcheck.bankid.no/oauth/tokenRequest#
The API client authenticates with a client assertion: a JSON Web Token (JWT) that it signs with its own private key (RFC 7523 (opens in a new tab)). To create one, see Client assertion.
Send the parameters in an application/x-www-form-urlencoded body. Send each parameter once.
| Parameter | Type | Required | Description |
|---|---|---|---|
grant_type | string | Yes | client_credentials (RFC 6749 (opens in a new tab)). |
client_assertion_type | string | Yes | urn:ietf:params:oauth:client-assertion-type:jwt-bearer. |
client_assertion | string | Yes | The client assertion. Create a new one for each request. |
scope | string | Yes | The scopes, separated by spaces. With handover:create, the API client can create sessions. With handover:read, it can read them. |
client_id | string | No | The client ID. If present, it must be the same as the iss and the sub of the client assertion. |
For example:
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:readResponse#
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"<<ACCESS_TOKEN>>",
"token_type":"Bearer",
"expires_in":900,
"scope":"handover:create handover:read"
}| Field | Type | Description |
|---|---|---|
access_token | string | The access token. |
token_type | string | Bearer. |
expires_in | number | The lifetime of the access token, in seconds. The default is 900. Read it from each response, because Stø can set a different lifetime for each API client. |
scope | string | The scopes of the access token, separated by spaces. |
Keep the access token, and use it until shortly before it expires. Leave a margin, for example 60 seconds, and then request a new access token with a new client assertion. If a Handover API request returns 401 Unauthorized, discard the access token: an access token can stop working before it expires, for example when Stø revokes it. Get a new access token, and send the request again once. The token endpoint does not issue refresh tokens.
Send the access token in the Authorization header of each Handover API request:
Authorization: Bearer <<ACCESS_TOKEN>>Errors#
An error response has a JSON body with an error code and, usually, an error_description, as RFC 6749 (opens in a new tab) describes. The error_description is for people. Do not use it to make programmatic decisions, because its text can change.
error | Status | Cause |
|---|---|---|
invalid_request | 400 | The Content-Type of the request is not application/x-www-form-urlencoded, or the request has a parameter more than once. The request also fails if it has a client_secret parameter and an Authorization header. |
invalid_client | 400 or 401 | Client authentication failed. For example, the authorisation server cannot find the public key, the signature or a claim is not correct, or the client assertion was used before. A request that uses a client assertion and another authentication method also fails. The status is 401, with a WWW-Authenticate header, if the request has an Authorization header. Otherwise, it is 400. |
unauthorized_client | 400 | The API client cannot use this grant type, or its set-up is not complete. Contact Stø. |
unsupported_grant_type | 400 | The request has no grant_type, or the authorisation server does not support its value. Use client_credentials. |
invalid_scope | 400 | The request has no scope, or it asks for a scope that the API client cannot use. |
server_error | 500 | An error occurred in the authorisation server. Try again later, with a new client assertion. |
For example, a request that sends a client assertion a second time gets this response:
HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
"error":"invalid_client",
"error_description":"client_assertion jti has already been used"
}Authorisation server metadata#
The authorisation server metadata (RFC 8414 (opens in a new tab)) gives the token endpoint, the client authentication methods, the signing algorithms and the scopes. Its issuer is the aud of each client assertion.
The metadata is at https://prod.idcheck.bankid.no/.well-known/openid-configuration (opens in a new tab). The same document is also at https://prod.idcheck.bankid.no/.well-known/oauth-authorization-server (opens in a new tab).
Client secret#
An API client that already has a client secret can still use it instead of a client assertion. Send the client ID and the client secret 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_id=<<CLIENT_ID>>&client_secret=<<CLIENT_SECRET>>&scope=handover:create+handover:readAlternatively, send them in an HTTP Basic Authorization header, as RFC 6749 (opens in a new tab) describes. Do not send them in both places: a request with both fails with invalid_request.
Next steps#
- Client assertion: create a key pair and sign client assertions.
- Create a session: use the access token to start an ID Check session.
- Fetch a session: use the access token to read the state of a session.