Signed URLs¶
LaterPay’s APIs expect signed URLs. LaterPay can also redirect their users to merchant websites using signed URLs.
Merchants can sign URLs using their secret key.
When the signature is calculated using
signing algorithm it is added to the url as
hmac query parameter. For example if the signature for a HTTP GET
request to http://example.net/abc?x=2 is fakesignature then following
are valid signed URLs:
http://example.net/abc?x=2&hmac=fakesignature
http://example.net/abc?hmac=fakesignature&x=2
LaterPay provides a /validatesignature endpoint where merchants can test if their URL signing process and their credentials are correct.
Signing algorithm¶
LaterPay APIs use following algorithm to calculate the signature for incoming requests:
Obtain the following:
secretsecret string used to sign the request. Example
"fakesecret".base_urlHTTP url consisting of scheme, host, path and without query and fragment parts. For example if a request went to
http://example.net/p/ath?f=v#fragthebase_urlwould be"http://example.net/p/ath"http_methodHTTP method used in the request. Examples:
"GET","POST","PUT","DELETE". Must be uppercase.paramsa list of key value pairs constructed from URL’s query string. There can be multiple pairs with the same key. Example
(("k2", "v1"), ("k1", "v2"), ("k1", "v1"))fromhttp://example.net/p/ath?k2=v1&k1=v2&k1=v1
Make sure
http_method,base_urland allparams(both keys and values) are UTF-8 encoded and percent encode them. For example:http_method:"GET"becomes"GET".base_url:"http://example.net/test"becomes"http%3A%2F%2Fexample.net%2Ftest"params:(("kæy", "vąl"), ("safe?", "1 + 2 = 3"), ("k1", "v2"), ("k1", "v1"))
becomes
(("k%C3%A6y", "v%C4%85l"), ("safe%3F", "1%20%2B%202%20%3D%203"), ("k1", "v2"), ("k1", "v1"))
Alphabetically sort
params. First by key and if there are multiple pairs with the same key then by value as well. For example(("k%C3%A6y", "v%C4%85l"), ("safe%3F", "1%20%2B%202%20%3D%203"), ("k1", "v2"), ("k1", "v1"))
should become
(("k%C3%A6y", "v%C4%85l"), ("k1", "v1"), ("k1", "v2"), ("safe%3F", "1%20%2B%202%20%3D%203"))
Join encoded and sorted
paramsinto one string by taking each key/value pair and joining it with"="and then joining the resulting pairs with"&". For example:(("k%C3%A6y", "v%C4%85l"), ("k1", "v1"), ("k1", "v2"), ("safe%3F", "1%20%2B%202%20%3D%203"))
becomes
"k%C3%A6y=v%C4%85l&k1=v1&k1=v2&safe%3F=1%20%2B%202%20%3D%203"
Now percent encode the
paramsstring. For example"k%C3%A6y=v%C4%85l&k1=v1&k1=v2&safe%3F=1%20%2B%202%20%3D%203"
becomes
"k%25C3%25A6y%3Dv%25C4%2585l%26k1%3Dv1%26k1%3Dv2%26safe%253F%3D1%2520%252B%25202%2520%253D%25203"
Create the
messagefor signing by joininghttp_method,base_urlandparamsstrings with"&". For example a message for a"GET"request tohttp://example.net/test?kæy=vąl&safe?=1 + 2 = 3&k1=v2&k1=v1would be"GET&http%3A%2F%2Fexample.net%2Ftest&k%25C3%25A6y%3Dv%25C4%2585l%26k1%3Dv1%26k1%3Dv2%26safe%253F%3D1%2520%252B%25202%2520%253D%25203"
Compute a HMAC using SHA-224 with
secretandmessage. This value HEX encoded and in lowercase is the signature. Signature created using a"fakesecret"secretand ourmessage:"GET&http%3A%2F%2Fexample.net%2Ftest&k%25C3%25A6y%3Dv%25C4%2585l%26k1%3Dv1%26k1%3Dv2%26safe%253F%3D1%2520%252B%25202%2520%253D%25203"
is
"cc4ddc63ed0bbea9d1cfad38e4a3f511608510713b33c4585bfa86dd".
Code Libraries¶
This is the list of code libraries implementing the signing scheme used by LaterPay: