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
Getting 401 when trying to access resource that requires auth #7
Comments
I'm seeing the same issue. When I "binding.pry" in the authenticate_user! method of my controller. I don't get a header called "access-token"
However,
I'm using jquery $.ajax which j-toker expects and sets the request headers in the beforeSend according to docs. Yet, inspecting the browser network tab does not show the Headers.
Adding this manually to jQuery, however, works. I was under the impression that this happened automatically? |
Same here unfortunately ... can't get it fixed with your suggestion. How exactly did you fix the issue @enricribas ? |
Hi, are you guys using the module with CommonJS or AMD? (using |
neither, just via the script tag. First jquery, deparam, cookies, pubsub then j-toker. should work right? |
It should work out of the box. Before the request was made, was the And also, is there anything else in your codebase that sets the |
No, neither of the values has been set ... |
That means the user hasn't been authenticated, or the authentication was unsuccessful for some reason. When you sign in, is the |
No it is not, seems like the getResponseHeader method does not "know" the keys "access-token" etc... just tried to debug your code but not sure yet why there is no return value ... |
It should work correctly if getResponseHeader or getAllResponseHeaders would return the token information. In the console I see the headers displayed correctly, but the functions only return Content-Type and Cache-Control. Maybe you have any idea what the reason for that could be? |
Are the headers returned by the server on a successful login? |
Yes, the header contains all valid info
|
Can you post your configuration block? |
$.auth.configure({ You mean this? |
@lynndylanhurley I also have the same problem. It seems that after a successful $(function() {
Auth.configure({
apiUrl: 'http://localhost:3000/api'
});
Auth.emailSignIn({
email: 'd@gmail.com',
password: '12341234',
}).then(function(user) {
console.log(user)
$.ajax ({
url: "http://localhost:3000/api/playlists",
type: "POST",
data: JSON.stringify({"playlist": {name: 'jjambbong'}}),
dataType: "json",
contentType: "application/json",
success: function(data){
console.log(data);
//401
}
});
})
// this block doesnt work either
// $.post("http://localhost:3000/api/playlists", {
// name: 'jjambbong'
// }, function(data) {
// console.log("playlist created");
// }) @lynndylanhurley Here are the response headers
|
Just a heads up -- I was having this same issue and for me this was caused because I was not exposing the correct headers in my cors configuration. For example I had:
Instead of:
Hope that helps |
Try this fix. |
Hello,
I'm using devise_token_auth and j-toker for authentication. To be fair this is my first time using it, but also to be fair I think I've read all of the important parts of the Readme. That said I have get it to signup and sign in/out, but can't seem to get $.getJSON to work with it. I'm not doing any custom ajax setup. Any help would be great!
To clarify, the way I am trying to make this work, as this is how I understand it to work, is to sign-in and then simply make the $.getJSON request on a button press after that. This gives me the following console message on the rails server: Filter chain halted as :authenticate_user! rendered or redirected
And then a 401 on the client side. I have verified that this all works perfectly manually, so it's something with the way I'm using j-toker.
Sorry if this is just me being stupid, but there isn't a lot out there about j-toker and I read everything in the readme that seemed applicable.
Thanks!
The text was updated successfully, but these errors were encountered: