Open Closed

Azure Ad B2C implementation #8269


0
HubOneSystems created

Hello,

I have follow the steps mentioned in the below link: https://support.aspnetzero.com/QA/Questions/7702

but still getting below error after redirected to the redirection url: got Exception message : Sequence contains no matching element

from file : TokenAuthController.cs method: private async Task<ExternalAuthUserInfo> GetExternalUserInfo(ExternalAuthenticateModel model) error line : var userInfo = await _externalAuthManager.GetUserInfo(model.AuthProvider, model.ProviderAccessCode);

Can you please provide the solution for the same?


10 Answer(s)
  • 0
    HubOneSystems created

    Any updates on above problem?

  • 0
    maliming created
    Support Team

    hi @HubOneSystems

    Sequence contains no matching element

    Can you share the full error stack in the log file?

    https://docs.aspnetzero.com/en/aspnet-core-mvc/latest/Features-Mvc-Core-Social-Logins#openid-connect-login

  • 0
    HubOneSystems created

    Hi @malining,

    Working on project core + angular latest version

    Please find below logs for this error: Stack trace error:

    at System.Linq.ThrowHelper.ThrowNoMatchException()
    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
    at Abp.AspNetZeroCore.Web.Authentication.External.OpenIdConnect.OpenIdConnectAuthProviderApi.<GetUserInfo>d__1.MoveNext()
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    at ProjectDemo.Web.Controllers.TokenAuthController.&lt;GetExternalUserInfo&gt;d__39.MoveNext() in 
    ...\Demo.Web.Core\Controllers\TokenAuthController.cs:line 492
    

    Error Logged in Logs.txt file:

    WARN  2020-01-02 16:15:14,755 [29   ] Mvc.ExceptionHandling.AbpExceptionFilter - Sequence contains no matching element
    Abp.UI.UserFriendlyException: Sequence contains no matching element
    at ProjectDemo.Web.Controllers.TokenAuthController.GetExternalUserInfo(ExternalAuthenticateModel model) in ...\Demo.Web.Core\Controllers\TokenAuthController.cs:line 504
    at ProjectDemo.Web.Controllers.TokenAuthController.ExternalAuthenticate(ExternalAuthenticateModel model) in ...\Demo.Web.Core\Controllers\TokenAuthController.cs:line 365
    at lambda_method(Closure , Object )
    at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
    at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    
  • 1
    ismcagdas created
    Support Team

    Hi,

    It seems like some of the required claims are missing or not mapped. Could you try adding mapping configuration like this https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/appsettings.json#L56 ?

  • 0
    HubOneSystems created

    Hi ismcagdas,

    I have already tried before the same from your previous comments on difference active directory b2c related issues, but not working before. But Now I have added below things in appsettings.json and it's working fine.

     "ValidateIssuer": "false",
          "ClaimsMapping": [
            {
                "claim": "unique_name",
                "key": "emails"
              },
            {
              "claim": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
              "key": "http://schemas.microsoft.com/identity/claims/objectidentifier"
            }
          ]
    

    Thanks a lot for help.

    Can you please help me out following things. 1. how to set Reset password policy for the Azure AD B2C 2. how to set Edit profile policy for the Azure AD B2C

    As I can on find the LoginURl field in OpenId in appsettings.json So can you please let know where I can add logic for policy cretaed for edit profile and reset password for external user login using AD B2C?

    Thanks.

  • 0
    HubOneSystems created

    Hello Any comments on above query.

    If I click on the forgot password link from the third party sign in page (opens after I click on log in with openidconnect from angular app) It gives me following error in angular app.

    core.js:4002 ERROR Error: Uncaught (in promise): OAuthErrorEvent: {"type":"token_error","reason":{},"params":{"error":"access_denied","error_description":"AADB2C90118:+The+user+has+forgotten+their+password.\r\nCorrelation+ID:+d7cf1acf-a8ec-0000-0000-7e290f1d362a\r\nTimestamp:+2020-01-09+09:54:37Z\r\nlogin_hint:+dev@mail.in\r\n","state":"Ln2xfKzgXGyD_6yCecWlUh9A6Cw1bY0YCxnoGeZitLi6Z;openIdConnect=1"}}
        at resolvePromise (zone.js:836)
        at resolvePromise (zone.js:795)
        at zone.js:897
        at ZoneDelegate.invokeTask (zone.js:431)
        at Object.onInvokeTask (core.js:26247)
        at ZoneDelegate.invokeTask (zone.js:430)
        at Zone.runTask (zone.js:198)
        at drainMicroTaskQueue (zone.js:611)
    defaultErrorLogger @ core.js:4002
    

    Where I need to set URL for Forgot password policy created in Azure ad b2c in OpenId section in appsettings.json ?

    OR need to manage differently in asp net zero. please suggest

    My project is Core + angular

  • 0
    ismcagdas created
    Support Team

    Hi @HubOneSystems

    Forgot password on AzureAD is not implemented on AspNet Zero side. Does Azure AD redirect you back to AspNet Zero site when you click forgot password link ?

  • 0
    HubOneSystems created

    Hello ismcagdas,

    yes, I am using Azure AD B2C. When I click on forgotpassword link from sign in page for external authentication using openID connect, It redirect me to the login page with below mentioned error. And It's keep showing loader on login page as Console error genrates due to this. core.js:4002 ERROR Error: Uncaught (in promise): OAuthErrorEvent: {"type":"token_error","reason":{},"params":{"error":"access_denied","error_description":"AADB2C90118:+The+user+has+forgotten+their+password.\r\nCorrelation+ID:+d7cf1acf-a8ec-0000-0000-7e290f1d362a\r\nTimestamp:+2020-01-09+09:54:37Z\r\nlogin_hint:+dev@mail.in\r\n","state":"Ln2xfKzgXGyD_6yCecWlUh9A6Cw1bY0YCxnoGeZitLi6Z;openIdConnect=1"}} at resolvePromise (zone.js:836) at resolvePromise (zone.js:795) at zone.js:897 at ZoneDelegate.invokeTask (zone.js:431) at Object.onInvokeTask (core.js:26247) at ZoneDelegate.invokeTask (zone.js:430) at Zone.runTask (zone.js:198) at drainMicroTaskQueue (zone.js:611) defaultErrorLogger @ core.js:4002

  • 0
    ismcagdas created
    Support Team

    Hi @HubOneSystems

    Thank you for your feedback. As I said, it is not implemented on AspNet Zero side. If you can create an issue on GitHub and share details for reproducing the problem, we can try to implement this.

    Thanks,

  • 0
    HubOneSystems created

    Hello @ismcagdas,

    I have generated issue on github please find the below links:

    https://github.com/aspnetzero/aspnet-zero-core/issues/2934