External Login, AuthenticationFailureException: "invalid_client" on callback #57
-
IdentityServer versionversion 7, latest release .NET version.net 8 DescriptionI am trying to setup an additional federated login in combination with a pushed autorisation request on our identity server. The first part of the external login process seems to work fine. The PAR request is handled and the user can login using the 3rd party server. However then the redirect back to our server produceds an Error 500. The error message indicateds that something is wrong with the client Id. Reproduction steps
receiving error: OpenIdConnectProtocolException: Message contains error: 'invalid_client', error_description: 'Invalid client: Possible causes may be missing / invalid client_id, missing client authentication, invalid or expired client secret, invalid or expired JWT authentication, invalid or expired client X.509 certificate, or an unexpected client authentication method', error_uri: 'error_uri is null'. Expected behaviorI would excpected that the Authorization Handler validates the query parameters and (external) signs in the user at this point. Then it redirects to the External Controller Callback Methode so I can manualy do what is needed and finally locally sign in the user after matching him with the local database. Logs[16:47:24 Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware
An unhandled exception has occurred while executing the request.
Microsoft.AspNetCore.Authentication.AuthenticationFailureException: An error was encountered while handling the remote login.
---> Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectProtocolException: Message contains error: 'invalid_client', error_description: 'Invalid client: Possible causes may be missing / invalid client_id, missing client authentication, invalid or expired client secret, invalid or expired JWT authentication, invalid or expired client X.509 certificate, or an unexpected client authentication method', error_uri: 'error_uri is null'.
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.RedeemAuthorizationCodeAsync(OpenIdConnectMessage tokenEndpointRequest)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleRemoteAuthenticateAsync()
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
at Duende.IdentityServer.Hosting.FederatedSignOut.AuthenticationRequestHandlerWrapper.HandleRequestAsync() in /_/src/IdentityServer/Hosting/FederatedSignOut/AuthenticationRequestHandlerWrapper.cs:line 39
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/DynamicProviders/DynamicSchemes/DynamicSchemeAuthenticationMiddleware.cs:line 51
at Duende.IdentityServer.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in /_/src/IdentityServer/Hosting/BaseUrlMiddleware.cs:line 27
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context) Additional contextSetup in Startup.cs o.Authority = mobileIdSettings.Authority;
I have been looking in the old support discussion and found these two threads. I looked into the solution from 889 together with the provider. I applied the fix from 889 but the event does not seem to get triggered at all. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The error you're seeing is most probably from the external identity provider. Can you somehow check what is going wrong there? Maybe you have access to the logs e.g. |
Beta Was this translation helpful? Give feedback.
-
I managed to find out what the problem was and why the authorization code exchange failed. With PAR in place this external IDP will enforce authentication not only on the PAR endpoint but also on the token endpoint. So when I received the authorization code and when trying to exchange the code for a token it rejected the request.
However, this is not working. When using a specifice class i.e. ParOidcEvents that inherits from OpenIdConnectEvents as shown in the Duende PAR example, the events will not fire in the Startup class. Muchmore one must overide the Methode in the ParOidcEvents class:
With this in place it works |
Beta Was this translation helpful? Give feedback.
I managed to find out what the problem was and why the authorization code exchange failed.
With PAR in place this external IDP will enforce authentication not only on the PAR endpoint but also on the token endpoint. So when I received the authorization code and when trying to exchange the code for a token it rejected the request.
I figured that out quite quickly and was trying to solve the problem by adding the suggested code from ticket 899 in my Startup.cs class, right where AddOpenIdConnect() is called and the setup of the external provider takes place.