EDIT:
Was able to give consent to the API by calling getAccessTokenWithPopup
. However still facing issues accessing private and private-scoped endpoints. They are still returning 401 Error.
ORIGINAL:
Found this post https://community.auth0.com/t/how-to-authorize-a-spa-to-access-an-api/56926. Even though I have assigned my user the permissions, I still get the following error in my browser console.
useEffect(() => {
const getUserMetadata = async () => {
try {
const accessToken = await getAccessTokenSilently({
audience: "https://webapp/api",
scope: "read:messages",
});
console.log(accessToken);
} catch (e) {
console.log("error ", e);
}
};
getUserMetadata();
}, [getAccessTokenSilently]);
Error: Consent required
at new OAuthError (errors.tsx:8:1)
at utils.tsx:15:1
at auth0-provider.tsx:326:1
at step (vendors~main.chunk.js:214:17)
at Object.throw (vendors~main.chunk.js:145:14)
at rejected (vendors~main.chunk.js:107:32)