Hi, we are trying to migrate our application to using Okta authentication/authorization. We’ve figured out how to authenticate the user and send the JWT token to our backend to authorize users, but now we are stuck with one problem. The backend will need to verify that a user exists in the security server, by performing a request via HttpClient. I’ve modified the original code to send the request to our okta authentication server, the code kinda looks like this below:
using ( var client = new HttpClient { BaseAddress = new Uri(oktaDomain) })
{
// get access token from request header.
var token = HttpContext.Current.Request.Headers["Authorization"].Replace("Bearer ", "");
// Add the current user's access token to the request.
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(BEARER_HEADER_NAME, token);
// Contact the server.
var response = client.GetAsync($"api/v1/users/{loginName}").Result;
// Get the results.
var content = response.Content.ReadAsStringAsync ().Result;
// Was the call successful?
if ( !response.IsSuccessStatusCode )
{
ProcessError ( response, content );
}
// Parse the result.
... Details hidden ...
}
Unfortunately, the code does not work and we keep getting 400 bad request. Inspecting the response object and we find that the error appears to be ‘The authorization server id is invalid’. Why does this happen? The authorization server appears valid when we make AJAX calls from the client side, and even the token can be obtained from HTTP request headers correctly. Please help.