mgomes / api_auth

HMAC authentication for Rails and HTTP Clients
MIT License
480 stars 147 forks source link

Issue with implenting this in JavaScript #167

Closed mbround18 closed 5 years ago

mbround18 commented 6 years ago

Hello All,

So I am attempting to write a JavaScript library based off of this gem so communication can be handled between something like an Angular app and an API in ruby however I am running into an issue. I believe I have everything correctly put together and all the bits and bobs set up for the library but for some reason its never authenticated.. Any help would be greatly appreciated. :)

As a side note, I know someone has built a node implementation of this already but I do not want to use browserify or something while building this out.

Here is the repository for the ApiAuth.js: https://github.com/mbround18/api-auth-js Here is the test repository which has the solution built into a web and api format but I cannot get it working: https://github.com/mbround18/api-auth-js-test

fwininger commented 6 years ago

Hello @mbround18

I have copy/paste your code in my console : https://github.com/mbround18/api-auth-js/blob/master/ApiAuth.js I run ApiAuth("test","test", "GET", "https://API_URL", "sha256") but I don't see any query on my server :'(

fwininger commented 6 years ago

Can you please give my a procedure to use your code (I'm not JS specialist)

mbround18 commented 6 years ago

@fwiniger I built a ruby based api test for this library. Please take a look at this repository https://github.com/mbround18/api-auth-js-test it has the api-auth-js as a submodule and when you run the Ruby code with bundle exec rackup and navigate to http://127.0.0.1:9292 in your browser it will automatocally send a request to the API. One you load the web page check the console to see the error I was talking about which is a 401 unauthorized error. I believe I have all the pieces of the canonical string properly assembled and properly hashed but for some reason even when I use try to authenticate the signed request it doesn't seem to work... Anyway as an FYI make sure to open 127.0.0.1:9292 in Chrome as for ease of use I used a CDN for CryptoJS which doesn't work in Firefox for some reason. I only did that for the example though.