Auth0 Home Blog Docs

Auth0.js - not returning the correct audience

jwt
javascript
audience

#1

Hi guys.

I am trying to create a front-end application that uses the auth0 javascript SDK. This works fine and returns a JWT token as expected. But when I want to call an API with the same token it didnt work since the token is not for that audience. I tried adding audience to the code but for some reason the token keep having the clientID as the aud.

var webAuth = new auth0.WebAuth({
    domain:       'domain.eu.auth0.com',
    clientID:     'VaNkT5yOxGXMtdN7UVlKdFGy7daCGOJ0',
    responseType:   'token',
    audience: 'https://myapi.com'
});

$('.signin-db').on('click', function() {
    webAuth.redirect.loginWithCredentials({
        connection: 'Username-Password-Authentication',
        username: $("#email").val(),
        password: $("#password").val(),
        scope: 'openid',
    }, function (err, authResult) {
        console.log(err);
    });
});

JWT

{
  "iss": "https://domain.eu.auth0.com/",
  "sub": "auth0|58e43f45902b27174fc065bed71",
  "aud": "VaNkT5yOxGXMtdN7UVlKdFGy7daCGOJ0",
  "exp": 1493923035,
  "iat": 1493887035
}

#2

Have you configured an API in Auth0 that corresponds to the https://myapi.com identifier?


#3