https://slingdata.io logo
Authentication
# sling-help
m
Hi, dealing with API Source that have specific authorization process. I have to generate value by sha256 algorithm based on next values: unix timestamp\epoch token uri (without base url) docs reference: https://docs.sumsub.com/reference/authentication#generate-app-token how to get unix timestamp? And if there is a way to do it in "authentication" specs?
f
try
date_format(now(), "%s")
Yeah, I think it would be worth adding to
authentication
block. Or I'm thinking as a function
hmac_sign_sha256
or something.
m
So, can I already implement this type of authentication? Or I'm missing some functionality?
f
It's missing functionality right now. I am refactoring the authentication code to better accommodate multiple auth schemes. Should be good in a few days, will let you know.
hey @marikt94 , check out https://docs.slingdata.io/~/revisions/b2HNnLvi9IyBoMktZsoX/concepts/api-specs/authentication#hmac-authentication use the latest dev build. I think for sumsub, the
signing_string
will be
"{unix_time}{http_method}{http_path}{http_body_raw}"
(according to [this](https://github.com/SumSubstance/AppTokenUsageExamples/blob/master/GoLang/GoLangAppTokensHmacSha256.go#L202-L212) ).
m
Great! I will check it soon, thanks alot!
Ok, I have tested it, and I guess that Im missing something.. I started debug the signature with sample values. I have switch the ts to constant '1' and secret_key also to '1', to see whats the signitire is and to comapre it from our process if its the same. From our side its a sql query that generated the signitire. So this is the example from postgres: select 1 || 'GET' || '/resources/auditTrailEvents/', encode(hmac(1 || 'GET' || '/resources/auditTrailEvents/', 'x', 'sha256'), 'hex') as "SIGNATURE" and for next set values '1GET/resources/auditTrailEvents/' the hash is 10ff7d902febd8bf3a00b7081b5448848fdb138816c119b9a04900ef62fe8f21 But when I testing the conection with trace I can see next signiture "test":"1GET/resources/auditTrailEvents/", "x-app-access-sig":"8df008312c30215dd7c57943321d7ba76c1b1414b131bfbc39ea0ab37a218d33",
f
what
signing_string
are you using? can you share your spec?
m
authentication: type: "hmac" algorithm: "sha256" # sha256 or sha512 secret: "{secrets.api_secret}" # signing_string: "{unix_time}{http_method}{http_path}" signing_string: "1{http_method}{http_path}" request_headers: test: "1{http_method}{http_path}" X-App-Access-Sig: "{signature}" X-App-Access-Ts: "{unix_time}" X-App-Token: '{secrets.token}' # nonce_length: 16 # Optional: generates random nonce (in bytes)
f
can you try
signing_string: "1{http_method}{http_path}/"
, do you have the ending slash in the URL path?
m
Hi, I already have a slash in the end pf url request
defaults: state: base_url: https://api.sumsub.com authentication: type: "hmac" algorithm: "sha256" # sha256 or sha512 secret: "{secrets.api_secret}" # signing_string: "{unix_time}{http_method}{http_path}" signing_string: "1{http_method}{http_path}" request_headers: test: "1{http_method}{http_path}" X-App-Access-Sig: "{signature}" X-App-Access-Ts: "{unix_time}" X-App-Token: '{secrets.token}' # nonce_length: 16 # Optional: generates random nonce (in bytes) endpoints: auditTrailEvents: request: url: '{state.base_url}/resources/auditTrailEvents/'
I guess I found the issue. I'll update if it success
f
also the latest dev build will give you HMAC details when you run with
--trace
, try it with that
m
When I try this: select encode(hmac('1', '{secrets.api_secret}', 'sha256'), 'hex') as "SIGNATURE" Im receive the same from conns test, it means that secret key isnt passed, but inside "request_headers" same syntax pass the secret key
Im used double qutes as the same in docs: authentication: type: "hmac" algorithm: "sha256" # sha256 or sha512 secret: "{secrets.api_secret}" # secret: "1" # signing_string: "{unix_time}{http_method}{http_path}" # signing_string: "1{http_method}{http_path}" signing_string: "1" request_headers: test: "{secrets.api_secret}" X-App-Access-Sig: "{signature}" X-App-Access-Ts: "{unix_time}" X-App-Token: '{secrets.token}'
And also tried with single quotes and without
May be I wasnt clear. Its looks like the secret key isnt passed to authentication. Because Im receive different hush.. So I tested it with sql query that we are using, and I can see that hash is match when I pass literly string "{secrets.api_secret}"
f
where are you running
select encode(hmac('1', '{secrets.api_secret}', 'sha256'), 'hex') as "SIGNATURE"
? as a hook?
m
Sorry, Im running it in our db, not in sling.. its something that runs in our legacy flow. the secret inside this formula is just a string with value = {secrets.api_secret}, and not parameter. So thats how I found that the api_secret didnt passed to the signiture.. But inside the request_headers i have "test" header that I passed there the api_secret and it looks that it passed fine
f
you're right, I see the issue, one sec
OK try latest dev build
m
Perfect! It works, thanks!