I have the user login to my WPF application using the Auth0 SDK. I then want the user to be able to access a WebAPI that I have. The WebAPI is setup in Auth0 as well. I can’t find any code examples that illustrate this process. I’ve followed the troubleshooter found here: Troubleshooting . I’ve had no success.
- I’ve confirmed my Domains match
- I’ve confirmed my ClientID \ Audiences match.
- I’ve confirmed I am using the correct decryption.
- I’ve configured the JWT middleware correctly using the code examples on the Auth0 website.
- My token has not expired.
I don’t receive an error in the Output window in Visual Studio. I simply receive a ‘StatusCode: 401, Unauthorized’ response.
I LOGIN AS FOLLOWS:
var client = new Auth0Client(new Auth0ClientOptions
{
Domain = "DOMAIN.auth0.com",
ClientId = "ABC123", //<-- ClientID of my application, NOT my WebAPI
Scope = "openid profile offline_access"
});
LoginResult loginResult = await client.LoginAsync();
I THEN TRY TO ACCESS MY API AS FOLLOWS:
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.BaseAddress = new Uri("https://localhost:12345/");
httpClient.SetBearerToken(loginResult.IdentityToken);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "api/products");
// request.SetBearerToken(loginResult.AccessToken);
HttpResponseMessage response = await httpClient.SendAsync(request);
}