The procedures to create the signature for using the SSOfy server can be summed up as follows:
Depending on the implementation, the recursive sort and value concatenation procedure may vary. Some programmers choose to do the recursive sort first before merging the results, while others may combine the two operations in a single iteration.
Path in the url starting with /
.
For instance, the path for a URL like https://api.ssofy.com/v1/authenticated/verify
is:
/v1/authenticated/verify
When generating signature for responses, path will be equivalent to the handler endpoint (current endpoint).
Salt should be a random string between 6 and 32 characters in length.
Here is a step-by-step breakdown of a sort and merge process:
Assuming we have a json payload like this:
{
"b": "Red",
"a": {
"c": "Blue",
"a": "Yellow",
"b": "Green"
}
}
The sorted object should resemble the following:
{
"a": {
"a": "Yellow",
"b": "Green",
"c": "Blue"
},
"b": "Red"
}
And here are the merged values:
YellowGreenBlueRed
YellowGreenBlueRed
Boolean values should be transformed into either 1
(true) or 0
(false).
Simple arrays should be considered index-associated since the iteration is over the keys of the array.
Example:
["A", "B", "C"]
=>
{
0: "A",
1: "B",
2: "C"
}
Given the following parameters:
URL | https://api.ssofy.com/v1/signature-test?mood=happy&dummy=true |
Data | { "b": "Red", "a": { "c": "Blue", "a": "Yellow", "b": "Green" } } |
Secret | SECRET-BETWEEN-US |
Salt | tUPDqF |
Our signature can be produced as follows:
- Combine all parameters of "query" and "form" into a single associative array.
{
"mood": "happy",
"dummy": true,
"b": "Red",
"a": {
"c": "Blue",
"a": "Yellow",
"b": "Green"
}
}
- Sort recursively by keys.
{
"a": {
"a": "Yellow",
"b": "Green",
"c": "Blue"
},
"b": "Red",
"dummy": true,
"mood": "happy"
}
- Iterate recursively through keys and merge values into a single linear string with no delimiters.
YellowGreenBlueRed1happy
- Concat PATH + VALUES + SALT.
/v1/signature-testYellowGreenBlueRed1happytUPDqF
- Hash the concatenated string using HMAC-SHA256 method.
49dfbcc23614133ad4823f8027cd3b583dcab0c811f2f844d84c2cf453987131
When including the signature in request or response headers, the format should be a base64 representation of a json object containing both hash and salt:
{
"hash": "49dfbcc23614133ad4823f8027cd3b583dcab0c811f2f844d84c2cf453987131",
"salt": "tUPDqF"
}
=>
Signature: ewogICAgImhhc2giOiAiNDlkZmJjYzIzNjE0MTMzYWQ0ODIzZjgwMjdjZDNiNTgzZGNhYjBjODExZjJmODQ0ZDg0YzJjZjQ1Mzk4NzEzMSIsCiAgICAic2FsdCI6ICJ0VVBEcUYiCn0=