UnauthorizedError: jwt audience invalid. expected: undefined
See original GitHub issueSorry, probably a PICNIC but I’ve converted https://github.com/connor11528/vuejs-auth-frontend to VueJS2 and it’s wired up to an instance of this server; LogIn/SignUp/LogOut are all working and the server’s creating, memorizing & returning an id_token back fine as long as the server instance is up. However when I call the protected random-quote I get a 401 response and the server logs
UnauthorizedError: jwt audience invalid. expected: undefined
…in the console.
getQuote() {
let token = auth.getAuthHeader();
console.log(token)
this.$http.get('http://localhost:3001/api/protected/random-quote', { headers: {
Authorization: token
}})
.then((data) => {
this.quote = data;
})
.catch((err) => console.log(err))
}
If I remove the authorization header the server logs the following in the console:
UnauthorizedError: No Authorization header was found
I’m certain I’m passing in the Authorization header in the “Bearer {jwt}” format correctly. What else am I missing?
Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImsiLCJpZCI6MiwiaWF0IjoxNDkzOTQyMjQ5LCJleHAiOjE0OTM5NjAyNDl9.RVrM7JL7D0ClQ-zOJijdJxZnUQHXVZKFO8wBvN469C8
xhr.js?14ed:177 GET http://localhost:3001/api/protected/random-quote 401 (Unauthorized)
dispatchXhrRequest @ xhr.js?14ed:177
xhrAdapter @ xhr.js?14ed:12
dispatchRequest @ dispatchRequest.js?91bc:52
xhr.js?14ed:177 XHR finished loading: GET "http://localhost:3001/api/protected/random-quote".
dispatchXhrRequest @ xhr.js?14ed:177
xhrAdapter @ xhr.js?14ed:12
dispatchRequest @ dispatchRequest.js?91bc:52
SecretQuote.vue?325d:31 Error: Request failed with status code 401
at createError (eval at <anonymous> (app.js:782), <anonymous>:15:15)
at settle (eval at <anonymous> (app.js:890), <anonymous>:18:12)
at XMLHttpRequest.handleLoad (eval at <anonymous> (app.js:761), <anonymous>:77:7)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:12 (4 by maintainers)
Top Results From Across the Web
UnauthorizedError: jwt audience invalid - Auth0 Community
Hi, I am trying to run a test in Postman to try out one of my protected end points with this implementation: const...
Read more >node.js - UnauthorizedError: jwt audience invalid. expected
You have created API scopes but I don't see any API resources in your code. Please add an API resource with the name...
Read more >Resolve Microsoft Graph authorization errors
401 Unauthorized error: Is your token valid? ... in the HTTP authenticate request header or that the token is invalid or has expired....
Read more >JSON Web Token Tutorial using AngularJS & Laravel - Toptal
aud: The audience of the token; exp: JWT expiration time defined in Unix time; nbf: “Not before” time that identifies the time before...
Read more >Troubleshooting JWT validation - Google Cloud
If the "aud" (audience) claim in a JWT token matches the Endpoints service name, then Cloud Endpoints Frameworks validates the audience and ignores...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @Mazzzy please try this:
Change
audience
toaud
in the jwtCheck function as seen in the above piece of code. That should work!@Mazzzy and @9swampy. This repo returns two tokens, an
id_token
and anaccess_token
. Theaccess_toke
n should be the token sent as an Authorization Header.Also, did you specify the audience in the backend when you cloned this repo?