-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any compatible javascript clients? #52
Comments
I've wondered the same thing. While I'm personally not aware of any, because this relies on the creation of a canonical string, I think that any library that follows the same signing algorithm would be compatible. I think the larger issue is that each client would need access to their private key in order to sign their requests. Where is this stored? Local storage? A cookie? Those things are (likely) ephemeral, meaning the user could easily lock themselves out of your app. I've been leaning more towards OAuth2 with a username/password flow instead for this very reason, as it's more in line with a typical authentication flow and doesn't require the user to permanently safeguard their token. Should they lose/delete the OAuth2 token, they'd just have to log in again. One could probably implement a similar workflow with this approach, but it doesn't seem as straightforward as OAuth2. Also, combining that with 3rd party authentication tokens might make things even more complex... Would be happy to get someone else's opinion on this, though. |
There are JS HMAC implementations so one could technically implement the entire algorithm in JS, but there is the issue of the private key. If your implementation uses a separate private key per user, then you could render the private key in the DOM. If you're using JQuery, you would then add the api_auth authorization header to each request. I'm sure other JS frameworks allow you to do the same. The only catch is to make sure the user that now has access to that private is allowed to see it. If, for example, your private key was account specific and each account had many users with various levels of permissions, you wouldn't want to render that private key in the page. |
I've got a similar question as to whether there are clients that will use this scheme in other languages as well (Java, Python, C++, etc.). Is this a custom approach, or one that has a common client implementation? |
What about the date? You can't set the date in an XHR, and this adds one for you. If you don't know the date, you can't create a proper signature. |
I'm facing the same problem. I did a quick search and this came up, https://www.thoughtworks.com/mingle/docs/configuring_hmac_authentication.html. Apparently Thoughtworks also uses this gem, and they've explained how to get around it without library support. I haven't tried it yet, but it looks pretty decent. |
https://www.npmjs.com/package/api_auth You'd have to use browserify. Older browsers also have appalling crypto support so I don't know how well it will work - but it's worth a shot.. |
Concerning the date issue mentioned by @bbhoss, I manage to circumvent it by using another header ( # When the client cannot set the `Date` HTTP header (for instance XHR),
# we use `X-Date` instead
if !request.headers.include? 'Date' and request.headers.include? 'X-Date'
request.headers['Date'] = request.headers['X-Date']
end |
I have made a Postman pre-request script to HMAC auth Postman requests, should be easy enough to convert it to node/browser js - https://gist.github.com/ctrlaltdylan/dd75426527d424bc7a4e93bc6a52ea95 |
For those that are looking for it, here is our JS api which works with api-auth:
Because you need the date/time stamp as part of the calc and CANNOT set that in a browser, we use
|
This gem looks cool, but I need to have JS clients access my API. Are there any specific JS libs that are known to work with ApiAuth?
The text was updated successfully, but these errors were encountered: