SIM Authentication using REST API (api_v100) #OLDER VERSION
Step by step instructions for service providers on how to communicate with our REST API for authentication using SIM certificate.
Table of Contents
- 1 Table of Contents
- 2 Requirements
- 3 Setup requirements used in the examples
- 4 Step 1
- 5 Step 2
- 5.1 Step 2: (Authenticate using mobile (SIM))
- 5.1.1 Callbacks
- 5.1.1.1 IDToken1 (_id: 0)
- 5.1.1.2 IDToken2 (_id: 1)
- 5.1.1.3 IDToken3 (_id: 2)
- 5.1.1.4 IDToken4 (_id: 3)
- 5.1.1.5 IDToken5 (_id: 4)
- 5.1.1.6 IDToken6 (_id: 5)
- 5.1.1.7 IDToken7 (_id: 6)
- 5.1.2 Example of the whole body in a call
- 5.1.3 CURL example of the call
- 5.1.4 C# - RestSharp example of the call
- 5.1.1 Callbacks
- 5.2 Step 2: Expected response
- 5.1 Step 2: (Authenticate using mobile (SIM))
- 6 Step 3
- 7 Step 4
- 8 Step 5
- 9 Step 6
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)
Redirect URI (Auðkenni receives from Service provider)
Information needed at runtime
User’s mobile number
Message text for user (Including any verification messages: number, text etc.)
Code challenge
Code verifier
Setup requirements used in the examples
Client id: myApiClientId
Client secret: MyApiClientP4$sW
Base URI: pfzww.audkenni.is
Redirect URI: http://localhost:3000/callback
All code examples are generated using Postman. They are therefore only for demo.
Step 1
Step 1: (Starting the authenticating process)
To start the authentication process an empty POST call is sent to following URI:
https://pfzww.audkenni.is:443/sso/json/realms/root/realms/audkenni/authenticate?authIndexType=service&authIndexValue=api_v100
Notice the Query parameter “authIndexValue”. It’s value is to select the REST API version to use.
CURL example of the call
curl --location --request POST 'https://pfzww.audkenni.is:443/sso/json/realms/root/realms/audkenni/authenticate?authIndexType=service&authIndexValue=api_v100' \
--header 'Content-Type: application/json' \
--header 'Accept-API-Version: resource=2.0,protocol=1.0' \
--data-raw '{}'
C# - RestSharp example of the call
var client = new RestClient("https://pfzww.audkenni.is:443/sso/json/realms/root/realms/audkenni/authenticate?authIndexType=service&authIndexValue=api_v100");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Accept-API-Version", "resource=2.0,protocol=1.0");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Step 1: Expected response
The REST API service answer is in JSON format.
The response should include following
authId (to use in next step)
callbacks (they need to be “answered” in nest step)
Example of answer from Step 1
{
"authId": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdXRoSW5kZXhWYWx1ZSI6ImFwaV92MTAwIiwib3RrIjoiNTY0djRwZnRrODFvM2RucmM2MnQ0bDVyNWoiLCJhdXRoSW5kZXhUeXBlIjoic2VydmljZSIsInJlYWxtIjoiL2F1ZGtlbm5pIiwic2Vzc2lvbklkIjoiKkFBSlRTUUFDTURJQUJIUjVjR1VBQ0VwWFZGOUJWVlJJQUFKVE1RQUNNRE0uKmV5SjBlWEFpT2lKS1YxUWlMQ0pqZEhraU9pSktWMVFpTENKaGJHY2lPaUpJVXpJMU5pSjkuWlhsS01HVllRV2xQYVVwTFZqRlJhVXhEU2paaFdFRnBUMmxLVDFRd05VWkphWGRwV2xjMWFrbHFiMmxSVkVWNVQwVk9RMUY1TVVsVmVra3hUbWxKYzBsdFJuTmFlVWsyU1cxU2NHTnBTamt1TG5Calh6ZHdTWGg2TWpaemJVUmxNVTFXTFhvNGVsRXViSEo2WjBSNE5uZEtUbU00WW01M1pWWkJaSFF4ZUZBdE4zRnNWbGs0Um5GamExOXJNMnRRYWtJNFdXSjBkV3REVkdaa1F6QnNMVFV0TjBwVmVITkRUM1ZYTjNwTlEweFFVMDVGVEd4QlVWZEVPRGhCU2tjNE5sUkxkVWhWTW14VGFHdFlURGxPUlVaeVIwWmpVbVp1VkZCU1NuUjFka2hwVUhnMmEzSmpiMkpYUzB0MVluRllZa1l4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xtRlNhRWh2TW1SNFJHOXZVR3BIYW5wRFpHWm5SM2MuZnl3eFVnQWhnQjJVNVA1UjVjNnduOVdORVB2Nm13akNNMzJmalhNc3d6SSIsImV4cCI6MTYxMDk2NjU1MywiaWF0IjoxNjEwOTY2MjUzfQ.OIuisFJ3LDA4WpKzDlfJMcu8tUgltFuyUCnto1WQzHo",
"callbacks": [
{
"type": "NameCallback",
"output": [
{
"name": "prompt",
"value": "Sláðu inn clientId"
}
],
"input": [
{
"name": "IDToken1",
"value": ""
}
],
"_id": 0
},
{
"type": "NameCallback",
"output": [
{
"name": "prompt",
"value": "Sláðu inn Related Party"
}
],
"input": [
{
"name": "IDToken2",
"value": ""
}
],
"_id": 1
},
{
"type": "NameCallback",
"output": [
{
"name": "prompt",
"value": "Sláðu inn símanúmer eða kennitölu"
}
],
"input": [
{
"name": "IDToken3",
"value": ""
}
],
"_id": 2
},
{
"type": "NameCallback",
"output": [
{
"name": "prompt",
"value": "Sláðu inn skilaboð til notanda"
}
],
"input": [
{
"name": "IDToken4",
"value": ""
}
],
"_id": 3
},
{
"type": "NameCallback",
"output": [
{
"name": "prompt",
"value": "Nota vchoice (true eða false)"
}
],
"input": [
{
"name": "IDToken5",
"value": ""
}
],
"_id": 4
},
{
"type": "NameCallback",
"output": [
{
"name": "prompt",
"value": "Sláðu inn Hash gildi"
}
],
"input": [
{
"name": "IDToken6",
"value": ""
}
],
"_id": 5
},
{
"type": "ChoiceCallback",
"output": [
{
"name": "prompt",
"value": "Veldu auðkenningarleið"
},
{
"name": "choices",
"value": [
"sim",
"card",
"app"
]
},
{
"name": "defaultChoice",
"value": 0
}
],
"input": [
{
"name": "IDToken7",
"value": 0
}
],
"_id": 6
}
]
}
Step 2
Step 2: (Authenticate using mobile (SIM))
To authenticate using mobile (SIM) another POST call is sent to following URI:
https://pfzww.audkenni.is:443/sso/json/realms/root/realms/audkenni/authenticate?authIndexType=service&authIndexValue=api_v100
Callbacks
There are 7 callbacks that needs to be answered in this call.
IDToken1 (_id: 0)
This callback need your Client Id as an input value (myApiClientId in this example)
Example of callback answer to send in call
IDToken2 (_id: 1)
This callback is for a “related party” information. To use if you have a client of your own you are authenticating for (you are acting as Identity provider for your customer).
The input value of this callback may be left with empty string (““) as an answer.
In this example we set the value as “MyOwnClient”.
Example of callback answer to send in call
IDToken3 (_id: 2)
This callback is for the mobile number you are using to authenticate. Here you put the mobile number of the person that is authenticating into the input value.
In this example we use the number “9876543”.
Example of callback answer to send in call
IDToken4 (_id: 3)
This callback is for the message sent to the user authenticating. A text message that is displayed on the users mobile.
If you use some kind of verification number or text you add it to the message.
In this example we use the message: “Authentication to Auðkenni - Code: 1234”
Example of callback answer to send in call
IDToken5 (_id: 4)
This callback is only for use when authenticating using APP. When authenticating using mobile (SIM) please set the input value to “false”.
Example of callback answer to send in call
IDToken6 (_id: 5)
This callback is only for use when authenticating using APP. When authenticating using mobile (SIM) please set the input value to an empty string ““.
Example of callback answer to send in call
IDToken7 (_id: 6)
This callback is for selecting authentication method. There are three options to select from: sim (0), card (1) and app (2).
Since we are authenticating using mobile (SIM) in this example, we set the input value to 0.
Example of callback answer to send in call
Example of the whole body in a call
CURL example of the call
C# - RestSharp example of the call
Step 2: Expected response
The REST API service answer is in JSON format.
When Step 2 is executed the authentication process at the users mobile starts.
The response should include following
authId (to use in next step)
callbacks (with waitTime and message)
Example of answer from Step 2
Step 3
Step 3: (Polling)
After executing Step 2 the authentication process at the users mobile starts. It depends on the user, the mobile device and the mobile 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 a tokenId which will in next step allow you get the Authentication Code. The tokenId is your login session token.
To poll for results we send yet another POST call to following URI:
https://pfzww.audkenni.is:443/sso/json/realms/root/realms/audkenni/authenticate
Body to send
This call need a JSON body sent with it, including two objects
authId (from last answer)
PollingWaitCallback (from last 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 similar answer as in Step 2.
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, using the authId from the last response. Each time you receive a new “waiting” answer you also receive a new authId to use next time.
The response should include following
authId (to use in next step)
callbacks (with waitTime and message)
Example of answer from Step 3
Step 3: Expected response (Authentication is finished)
When authentication process is finished successfully you will receive answer with a tokenId which will in next step allow you get the Authentication Code. The tokenId is your login session token.
The REST API service answer is in JSON format.
The response should include following
tokenId (to use in next step)
successUrl
realm
Example of answer from Step 3
Step 4
Step 4: (Get Authentication Code)
Now, when we have our login session token we can continue to next step, which is to get our Authentication Code.
To get the Authentication Code we send a GET call to following URI:
https://pfzww.audkenni.is:443/sso/oauth2/realms/root/realms/audkenni/authorize?service=api_v100&client_id=myApiClientId&response_type=code&scope=openid profile signature&code_challenge=5WnuXW4ALVNtX9G6MydkrPs-F2suz0TQkoaKBsk8Hzk&code_challenge_method=S256&state=abc123&redirect_uri=http://localhost:3000/callback
Header needed in the call
For this call to work we need to add a header object. It should be Cookie with the value “audsso=the tokenId from last call”.
Query parameters needed in the call
client_id
scope (openid, profile, signature)
code_challenge (search for info about code_challenge and code verifier)
state (search for info about state)
redirect_uri
CURL example of the call
C# - RestSharp example of the call
Step 4: Expected response
The JSON body of the answer should simply contain a “1”.
Header in response
You should receive following header object in the answer
Location (should contain URI with a query parameter named “code”
This “code” parameter is the Authentication Code you will use for the exchange process in next step.
Example of “code” in response
Step 5
Step 5: (Exchange Authentication Code with Access and Id token)
Now that we have the Authentication code we can finally ask for the Access and Id token of the user authenticated.
To exchange the Authentication Code for Access and Id token we send a 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 parameters
client_id
redirect_uri
code_verifier (search for info about code_challenge and code verifier)
code (the Authentication Code from last step)
client_secret
CURL example of the call
C# - RestSharp example of the call
Step 5: Expected response
The answer from this call should give you the Access and Id tokens along scope info, type and lifetime.
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
id_token
scope
token_type
expires_in (lifetime of the tokens)
Example of answer from step 5
Example of the payload in Access token
Example of the payload in Id token
Step 6
Step 6: (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 parameters
Authorization (Bearer, using the Access token from last call as value)
CURL example of the call
C# - RestSharp example of the call
Step 6: 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 6