Closed senzacionale closed 1 month ago
I'm currently updating my asp.net mvc app, that uses the duende identity server for authentication, to dotnet 8 and am getting this error as well. It worked fine when the asp.net mvc app was dotnet 7 and the identity server app was dotnet 8. It's when they are both dotnet 8 I get the problem.
It seems to be something to do with the tokenendpoint
. In the snippet below it's always empty even though the rest of the openid url's seem to be getting correctly extracted from the identity server metadata:
OnAuthorizationCodeReceived = context =>
{
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<Startup>>();
logger.LogInformation("OnAuthorizationCodeReceived: Authorization code received.");
logger.LogInformation($"Token Endpoint: {context.TokenEndpointRequest.AuthorizationEndpoint}");
logger.LogInformation($"Redirect Uri: {context.TokenEndpointRequest.RedirectUri}");
// Check if the token endpoint request is properly configured
var tokenEndpointRequest = context.TokenEndpointRequest;
if (tokenEndpointRequest == null)
{
logger.LogError("TokenEndpointRequest is null.");
}
else
{
logger.LogInformation($"TokenEndpointRequest: {tokenEndpointRequest}");
logger.LogInformation($"ClientId: {tokenEndpointRequest.ClientId}");
logger.LogInformation($"ClientSecret: {tokenEndpointRequest.ClientSecret}");
logger.LogInformation($"Code: {tokenEndpointRequest.Code}");
logger.LogInformation($"RedirectUri: {tokenEndpointRequest.RedirectUri}");
}
return Task.CompletedTask;
},
Logs:
[23:41:52 INF] OnAuthorizationCodeReceived: Authorization code received.
[23:41:52 INF] Token Endpoint:
[23:41:52 INF] Redirect Uri: https://localhost:5001/signin-oidc
[23:41:52 INF] TokenEndpointRequest: Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectMessage
[23:41:52 INF] ClientId: <snip>
[23:41:52 INF] ClientSecret: <snip>
[23:41:52 INF] Code: <snip>
[23:41:52 INF] RedirectUri: https://localhost:5001/signin-oidc
[23:41:52 DBG] Redeeming code for tokens.
[23:41:52 ERR] Exception occurred while processing message.
System.InvalidOperationException: An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.RedeemAuthorizationCodeAsync(OpenIdConnectMessage tokenEndpointRequest)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleRemoteAuthenticateAsync()
Please check this https://github.com/DuendeSoftware/Support/issues/1221
Solve my problem.
When I want to open admin page I am getting this error Either the request URI must be an absolute URI or BaseAddress must be set.
An unhandled exception occurred while processing the request. InvalidOperationException: An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set. System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
AuthenticationFailureException: An error was encountered while handling the remote login. Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()
Do we need to set BaseAddress somewhere?