gt2960
June 18, 2024, 8:15pm
1
I am trying to generate a JWT token with the getAccessTokenSilently, but when I try to add the audience parameter to the function I get this error: “No overload matches this call.”.
Here is the react typescript code snippet:
function App() {
const {user, isAuthenticated, isLoading , getAccessTokenSilently} = useAuth0();
const [token, setToken] = useState();
useEffect(() => {
(async () => {
try {
const accessToken: any = await getAccessTokenSilently({
audience: ‘API_IDENTIFIER’
});
setToken(accessToken);
} catch (error) {
console.error(‘Error fetching access token’, error);
}
})();
}, [getAccessTokenSilently]);
What can I do to fix this?
tyf
June 18, 2024, 8:52pm
3
Hey there @gt2960 !
I’m not positive what that error means, but passing the audience param in authorizationParams
may resolve it:
const accessToken = await getAccessTokenSilently({
authorizationParams: {
audience: "API_IDENTIFIER"
}
1 Like
gt2960
June 18, 2024, 11:40pm
4
Thanks that worked! What should go inside of the “API_IDENTIFIER” field?
1 Like
tyf
June 19, 2024, 2:26pm
5
Awesome, thanks for confirming!
The API_IDENTIFIER
field is the identifier which you give an API when registering it in Auth0:
gt2960
June 19, 2024, 3:56pm
6
Does it matter which API I use?
tyf
June 19, 2024, 4:53pm
7
Yes, the audience should be that of the resource server or API the access token is meant to be used to access.
system
Closed
July 3, 2024, 4:54pm
8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.