SIM Authentication using CIBA

Step by step instructions for service providers on how to Authenticate using CIBA and SIM certificate.

Table of Contents

 

Requirements

For all steps to be successful the following must be at hand.

During setup

  • Client Id (received from Auðkenni)

  • Client secret (received from Auðkenni)

  • Related party (not necessary)

  • Base URI (received from Auðkenni)

  • Private Key (to sign a JSON Web Token)

  • Public Key (to give to Auðkenni for configuration)

Information needed at runtime

  • User’s mobile number

  • Message text for user (Including any verification messages: number, text etc.)

 

Setup requirements used in the examples

  • Client id: myCibaClientId

  • Client secret: MyApiClientP4$sW

  • Base URI: pfzww.audkenni.is

  • Private Key: Not shown here for security reasons

  • Public Key: Not shown

All code examples are generated using Postman. They are therefore only for demo.

 

Step 1

Step 1: (Creating JSON Web Token)

The first step is to create a signed JWT to use for CIBA communication.

What the JWT need to include

  • login_hint (the users mobile number)

  • scope (openid, profile, signature. Also possible to add “related party” info here (see example))

  • acr_values (“sim-auth”. This value is different between authentication/signing methods)

  • iss (the Client id)

  • aud (Should have “https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni“)

  • exp (the lifetime of the token)

  • binding_message (the message to display at users mobile device)

  • binding_content (Used when signing, contains a hash of the content to sign)

Also needed to create the JWT

  • Private key (to sign the JWT)

  • Alg info (Should be “RS256”)

Example of JWT

eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJsb2dpbl9oaW50IjoiOTg3NjU0MyIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgc2lnbmF0dXJlIFJFTEFURURQQVJUWTpNeU93bkNsaWVudCIsImFjcl92YWx1ZXMiOiJzaW0tYXV0aCIsImlzcyI6Im15Q2liYUNsaWVudElkIiwiYXVkIjoiaHR0cHM6Ly9wZnp3dy5hdWRrZW5uaS5pczo0NDMvc3NvL29hdXRoMi9yZWFsbXMvcm9vdC9yZWFsbXMvYXVka2VubmkiLCJleHAiOjE2MTEwNzExMzEuNDUzLCJiaW5kaW5nX21lc3NhZ2UiOiJBdXRoZW50aWNhdGlvbiB0byBBdcOwa2VubmkiLCJiaW5kaW5nX2NvbnRlbnQiOiIifQ.U33KUKuVZ0OMgLinOIbWyGD6xabEH9DdeQl-z_tOzPxvt5h5_U8ZflDc5S1-3C3UOPfPvigxyUIWSscUB6Supk62FLLPKbwABqHnpjvama5p7NZrZ-FtD6mHpiGvN6Z9r-L5idtY8RsLSi912Av6xOh0QyjgUIySRQEInOrkkOQyNXsS-1N0ry2rQmhIyDJ6SCkvH3RlTSQY2T-e7iQuStdoYT-nWxaY_vvY3ZEbmly2GulWb1LGAfuow3RcQcBAzxyhhYt1LXHABkzoBdZeJc0ny-36j19GWhXbw2wMtMn6Gc9QF3UgxukW-dNDdQq8I_CaACZFIOQzpNO-Yki8MA

 

Example of JWT Payload

{ "login_hint": "9876543", "scope": "openid profile signature RELATEDPARTY:MyOwnClient", "acr_values": "sim-auth", "iss": "myCibaClientId", "aud": "https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni", "exp": 1611071131.453, "binding_message": "Authentication to Auðkenni", "binding_content": "" }

 

 

Step 2

 

Step 2: (Authorize)

To authorize using mobile (SIM) we send a POST call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/bc-authorize

 

Parameters needed in call

We need to add following header parameter

  • A Basic Auth header, using the Client id and Client secret

We need to add following parameter

  • request (the value should be the JWT from step 1)

 

CURL example of the call

curl --location --request POST 'https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/bc-authorize' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Authorization: Basic bXlDaWJhQ2xpZW50SWQ6TXlBcGlDbGllbnRQNCRzVw==' \ --data-urlencode 'request=eyJ0eXAiOiJKV1QuLCJhbGciOiJSUzI1NiJ9.eyJeb2dpbl9oaW58IjoiNjE3ODg4OCIsInNjb3BlIjoib3BlbmlkIHByb2ZpbGUgc2lnbmF0dXJlIFJFTEFURURQQVJUWTpNeU93bkNsaWVudCIsImFjcl92YWx1ZXMiOiJzaW0tYXV0aCIsImlzcyI6Im15Q2liYUNsaWVudElkIiwiYXVkIjoiaHR0cHM6Ly9wZnp3dy5hdWRrZW5uaS5pczo0NDMvc3NvL29hdXRoMi9yZWFsbXMvcm9vdC9yZWFsbXMvYXVka2VubmkiLCJleHAiOjE2MTEwNzIxODQuOTkyLCJiaW5kaW5nX21lc3NhZ2UiOiJBdXRoZW50aWNhdGlvbiB0byBBdcOwa2VubmkiLCJiaW5kaW5nX2NvbnRlbnQiOiIifQ.a0NM11W2PNyfzki-gHTrQZqVhuNgL6Uh4sjQQy96lHsfD1NkVe7h-41JT9to-c710GpSvF1ExAcb7b7Bjmy6Ep0M3BVuz066fzv0YfiIHbXd6pQIEXVqUxHQ6mteW1MmaI-xsYDgG_ahXS7ZD8VrN2y1hOGUt1P4kMnVkWVpSQBjolxsZdV1HYn7n9Iy1z0gNaZb_3EIiNGLAHzI2zaDG4x0SFl-vkslf0eqfBMyEquKNFeoBqLLW7WT-PXpIaCQuJ_7ohqbx-pO_JI9Hm2Fv-VH9HoXUhsXWxig3YcQVqYBzq5aEdrE_mulCJMGeCWM02HTxpHennN5GdttlGVksg'

 

C# - RestSharp example of the call

 

 

Step 2: Expected response

The CIBA service answer is in JSON format.

When Step 2 is executed the authentication process at the users device starts.

The response should include following

  • auth_req_id (to use in next step)

  • expires_in (the lifetime of th id)

  • interval

 

Example of answer from Step 2

 

 

Step 3

 

Step 3: (Poll for token)

After executing Step 2 the authentication process at the users device starts. It depends on the user, the device and the network how long time this process takes.

In this step we poll for results from the authentication process. When authentication process is finished successfully you will receive answer with Access and Id token of the user authenticated.

To poll for tokens we send another POST call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/access_token

 

Parameters needed in call

We need to add following header parameter

  • A Basic Auth header, using the Client id and Client secret

We need to add following parameter

  • grant_type (the value should be: “urn:openid:params:grant-type:ciba”)

  • auth_req_id (the value should be the auth_req_id from last step answer)

 

CURL example of the call

 

C# - RestSharp example of the call

 

 

Step 3: Expected response (Authentication still in process)

If you run the poll call before the user authentication process is finished you will receive a answer notifying the process isn’t finished.

The REST API service answer is in JSON format.

If you get answer like this you need to wait for short time and run Step 3 call again.

The response should include following

  • error_description

  • error

Example of answer from Step 3

 

Step 3: Expected response (Authentication is finished)

The answer from this call should give you the Access and Id tokens along type and lifetime info.

The Id token contains a PKCS7 signature. The signature contains a authentication certificate.

The REST API service answer is in JSON format.

Best practice

Best practice is to verify the signature and the certificate. Verify the user’s info in the Id token against the certificate in the signature.

The response should include following

  • access_token

  • scope

  • id_token

  • token_type

  • expires_in (lifetime of the tokens)

Example of answer from step 3

 

Example of the payload in Access token

 

Example of the payload in Id token

 

 

 

Step 4

 

Step 4: (Userinfo)

Here we ask for the users info using the Access token as Authorization header parameter.

To get the Userinfo we send a POST call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/userinfo

Parameters needed in call

We need to add following header parameter

  • Token (Bearer, using the Access token from last call as value)

 

CURL example of the call

 

C# - RestSharp example of the call

 

 

Step 4: Expected response

The answer from this call should give you a PKCS7 Signature. The same signature as is in the Id token from last step.

The signature contains a authentication certificate.

The REST API service answer is in JSON format.

Best practice

Best practice is to verify the signature and the certificate. Verify the user’s info in the answer against the info in the certificate.

The response should include following

  • signature (PKCS7)

  • documentNr (should be “na”)

  • certificate (should be “na”)

  • nationalRegisterId (The social id number of the user)

  • name (The users name)

  • sub (A unique Id of the user in our system)

  • subname (A unique Id of the user in our system)

Example of answer from step 4