Hash verification
Once a resource owner (RO) authorizes a client software, the authorization server (AS) will redirect the RO’s identity provider (IdP) to the finish URI if the client had provided an interact.finish
object in the intial request. In order to secure this communication and verify that the redirect indeed emanated from the AS, the AS will provide a hash parameter in the request to the client’s callback URI. The client must verify this hash.
Hashing method
The hash base is generated by concatentating the following values in sequence using a single newline (/n)
character to separate them:
nonce
value sent by the client in the initial request.nonce
value returned from the AS after the initial grant request.interact_ref
returned from the AS in the interaction finish method.- The grant endpoint
uri
the client used to make its initial request.
The following example shows the four aforementioned components that make up the hash base. There is no padding or whitespace before or after each line and no trailing newline character.
Example hash base
The ASCII encoding of this string is hashed with the sha-256
algorithm, which is the only hashing algorithm currently supported by Open Payments. The byte array from the hash function is then encoded using Base64 with no padding. The resultant string is the hash value.
Using our hash base string example above, the following is the sha-256
encoded hash that uses the 256-bit SHA2 algorithm.
SHA2 256-bit hash example
Verifying hash
When the client receives a redirect from the AS, the AS will include the hash parameter in the response. The client must calculate this exact value by concatenating the fields referenced above and then applying the sha-256
hashing algorithm. If the hash value matches the parameter sent by the AS, then the client can be certain the redirect emanated from the AS.
The example below demonstrates how to verify the hash received from the AS using a function in Javascript.
JavaScript example
Further reading
For more information refer to the Calculating the interaction hash section of the GNAP specification.