Base solution for your next web application
Open Closed

OpenId setup using Azure Active Directory - Error ValidateIssuer #6736


User avatar
0
terry21 created

I was able to set up Azure Active Directory authentication in the past using the old ASP.NET MVC 5.x and jQuery but have not been able to get it working with the Asp.Net Core / Angular 7 (version 6.7.0)

I have registered the application in Azure Active Directory and granted the API pemission

I have set up the parameters in appsettings.json based on the information in Azure

"OpenId": {
  "IsEnabled": "true",
  "ClientId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "Authority": "https://sts.windows.net/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/",
  "LoginUrl": "https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/authorize"
},`

I go to my Asp.NetZero application login screen and click in the OpenId icon. It prompts me correctly for a microsoft username and password as expected using the Microsoft and returns a token to the Login page but tht is when I get the following error:

INFO 2019-03-29 11:51:45,083 [4 ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
INFO 2019-03-29 11:51:45,310 [4 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method AspenTechnology.AspenPortal.Web.Controllers.TokenAuthController.ExternalAuthenticate (AspenTechnology.AspenPortal.Web.Core) with arguments (AspenTechnology.AspenPortal.Web.Models.TokenAuth.ExternalAuthenticateModel) - Validation state: Valid
ERROR 2019-03-29 11:51:53,509 [4 ] Mvc.ExceptionHandling.AbpExceptionFilter - The given key 'ValidateIssuer' was not present in the dictionary.
System.Collections.Generic.KeyNotFoundException: The given key 'ValidateIssuer' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Abp.AspNetZeroCore.Web.Authentication.External.OpenIdConnect.OpenIdConnectAuthProviderApi.ValidateToken(String token, String issuer, IConfigurationManager`1 configurationManager, CancellationToken ct)
at Abp.AspNetZeroCore.Web.Authentication.External.OpenIdConnect.OpenIdConnectAuthProviderApi.GetUserInfo(String token)
at AspenTechnology.AspenPortal.Web.Controllers.TokenAuthController.GetExternalUserInfo(ExternalAuthenticateModel model) in C:\TFSWorkspace\Aspen Portal\Template\aspnet-core\src\AspenTechnology.AspenPortal.Web.Core\Controllers\TokenAuthController.cs:line 476
at AspenTechnology.AspenPortal.Web.Controllers.TokenAuthController.ExternalAuthenticate(ExternalAuthenticateModel model) in C:\TFSWorkspace\Aspen Portal\Template\aspnet-core\src\AspenTechnology.AspenPortal.Web.Core\Controllers\TokenAuthController.cs:line 351
at lambda_method(Closure , Object )
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
INFO 2019-03-29 11:51:54,157 [4 ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
INFO 2019-03-29 11:51:54,240 [4 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action AspenTechnology.AspenPortal.Web.Controllers.TokenAuthController.ExternalAuthenticate (AspenTechnology.AspenPortal.Web.Core) in 9156.2841ms
INFO 2019-03-29 11:51:54,254 [4 ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'AspenTechnology.AspenPortal.Web.Controllers.TokenAuthController.ExternalAuthenticate (AspenTechnology.AspenPortal.Web.Core)'
INFO 2019-03-29 11:51:54,305 [4 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 9256.5662ms 500 application/json; charset=utf-8

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    What is your XXXWebHostModule.cs file code?

  • User Avatar
    0
    terry21 created

    It is as was downloaded except for removal of the Google and Facebook isEnabled if clauses as these two authentication providers will never be enabled.

  • User Avatar
    0
    maliming created
    Support Team

    try add ValidateIssuer in appsettings.json

    https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Host/appsettings.json#L41

  • User Avatar
    0
    terry21 created

    Thank you VERY much! I added the ValidateIssuer entry to the appsettings.json file and to the xxxWebHostModule.cs and it worked.

  • User Avatar
    0
    maliming created
    Support Team

    😊