Auth0 implementation with Angular and .Net Cire

I have created an API and an SPA in my dashboard and I have tested the API using postman and it all works fine.
In my Angular application I replaced my auth.service, auth.guard with the ones in the SPA getting started example and was able to login, which is good. Then I needed to communicate with my API, so I used this repo:

And took the interceptor there and added the new method getTokenSilently$ which appeared to work. But my API returns a 401 unauthorised response.

If I look in the console, I can see that the bearer token it is sending is significantly shorter than the one I pasted into postman:

Bearer 5Pn186637eLfc_lqCGK-P4u2YCuHXCNR


Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InJhaGpWejlJUnI3eElxZDRaYmJiYyJ9.eyJpc3MiOiJodHRwczovL3IzcGxpY2EuZXUuYXV0aDAuY29tLyIsInN1YiI6IkdXN2RJcElEZ3BUOXJPM05RT3hZOFlKUWtKcGpTWVY3QGNsaWVudHMiLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo0NDM5Mi8iLCJpYXQiOjE1ODc2NDcwNzgsImV4cCI6MTU4NzczMzQ3OCwiYXpwIjoiR1c3ZElwSURncFQ5ck8zTlFPeFk4WUpRa0pwalNZVjciLCJndHkiOiJjbGllbnQtY3JlZGVudGlhbHMifQ.a305uDzFalEw8-enE-L3BWOjm6LsMN8eWJjun_FISMy3JgG6aD0-bKZHVI1txBeEHRHva3Omc-vTcT2E1fBfD1TMiAelhaIpKduqzk2dN9fab85PioqKDlCf62QtOudd35WUcbBfriq1-e1JEv9HYYOblWe-6jGQstK77d1kNRC13uwQdA0pYF3Dbh8rScVIG7P2VWFJwE_0zdcddpj2u1bfQInCn8rbc7bst_DbRIA7QMKRgNT1p90hhoeo40hM1_TM5iBuXVJG9j5sXQ4StsWzSw7l_p8IZv8Uy_ayMFX2Rawu7JGmgCcw1uOJmmPJ_G8FjIfQWrU5NkDza98EGg

Does anyone know why? I assume it is a simple fix, but I am not sure what to do…

Hmm, I figured this out. It’s not very well documented, but you have to include the audience when making your call. To find the audience, you simply look at your apis in your dashboard and it states the audience there:

1 Like

Thanks for sharing it with the rest of community!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.