so,how can i get “Access Token” with above sdk.
There is a good Angular Quickstart demonstrating this (fetching the token, making a backend/API call):
https://auth0.com/docs/quickstart/spa/angular2/02-calling-an-api#calling-the-api
const client = await this.authService.getAuth0Client();
const token = await client.getTokenSilently();
return this.httpClient
.get('/api/external', {
headers: {
Authorization: `Bearer ${token}`
}
})
in “createAuth0Client” what is the use of “scope” param in createAuth0Client options
- in above thread u said “const token = await client.getTokenSilently();”
what will return “getTokenSilently()”
actuvally i am getting something like"21h3SAHv0oLqTevhxPAL91muyfj9SE" .
what will return “getTokenSilently()”
You can check the API docs here:
https://auth0.github.io/auth0-spa-js/classes/auth0client.html#gettokensilently
If there’s a valid token stored, return it. Otherwise, opens an iframe with the
/authorize
URL using the parameters provided as arguments. Random and securestate
andnonce
parameters will be auto-generated. If the response is successful, results will be valid according to their expiration times.
actuvally i am getting something like"21h3SAHv0oLqTevhxPAL91muyfj9SE" .
This looks like an access token in opaque string format, not JWT. This is because you didn’t define the audience
(that should be the API identifier of your API registered in Auth0 under Dashboard > APIs) in the request. See https://auth0.github.io/auth0-spa-js/interfaces/gettokensilentlyoptions.html#audience
Something like:
const token = await client.getTokenSilently({audience: 'https://example-api/});
. // replace with your own proper API identifier
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.