I’m new to the Auth0 and angularjs. I start a project using these two technology. I got a problem wile i’m doing this. I manage to get the security token using user name and password. I wanted a custom login page so I didn’t use the lock I used API endpoint. Then I need to get the user info using the token. I used https://auth0_domain/userinfo
endpoint for this. Using Postman it’s working fine but in my project it always sending 401 (Unauthorized) error. Below is my code. I tried everything on the internet
let url = "https://auth0_domain/userinfo";
let headers = new Headers({'Authorization': 'Bearer ' + this.getToken()});
return this.http.get(url, {headers})
.map((res: Response) => res.json())
.subscribe(res => console.log('res'));
The information you provided is not sufficient to provide a definitive answer. You should check the following answer to a similar question to see if it might apply to your situation.
The /userinfo endpoint returns 401 (Unauthorized)
Have in mind that the endpoint in question needs to be called with an access token and not with an ID token. In addition, if you can make it work in Postman, hardcode the token that works in your Angular application as that will let you discover if the source of the problem is token related or the way the application is performing the request.
Thanks for the reply. I’m passing the access token not the ID token. to me it seems like header is not passing. I tried it without any headers and still get the same error. I tried to hard code the token and still not working.
Yeah, your suggestion would indeed explain it. Try to review the request in the browser tools or any other HTTP capturing tool.
I found the problem. When I’m passing the token it comes with extra pair of quotations.
“Bearer “eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1N…””
I used JSON.parse() and now it’s working. I hope this will help to someone who has the same problem. Thank You
I found the problem. When I’m passing the token it comes with extra pair of quotations.
“Bearer “eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1N…””
I used JSON.parse() and now it’s working. I hope this will help to someone who has the same problem. Thank You