Base solution for your next web application

Activities of "konverto"

Hi Richard, do you maybe have any hints on the issue i posted above (yesterday)? any help is very appreciated!!

Thanks in advance

Good morning,

sorry I have to bother again, but I just don't seem to get this to work. I've tried several "project variants", and right now I'm trying with the same settings as @richardghubert (2019-02-04 ASP.NET CORE MVC & jQuery .NET Core 2.2 v6.5.0)

When I run ANZ and click on the "open id connect" login button, it redirects me to the b2c and right back to the "http://localhost:62114/Account/Login?ReturnUrl=%2FApp", without even showing me the b2c login page.

I followed the instructions provided and made the code changes in

RvsMvcJquery65Demo\src\RvsMvcJquery65Demo.Web.Mvc\appsettings.json

 "OpenId": {
  "IsEnabled": "true",
  "Authority": "https://mytenant.b2clogin.com/mytenant.onmicrosoft.com/oauth2/v2.0/authorize",
  "ClientId": "myclientid",
  "ValidateAudience": false
}

and added the mentioned code to RvsMvcJquery65Demo\src\RvsMvcJquery65Demo.Web.Host\Startup\AuthConfigurer.cs

if (bool.Parse(configuration["Authentication:OpenId:IsEnabled"]))
        {
            authenticationBuilder.AddOpenIdConnect(options =>
            {
                options.ClientId = configuration["Authentication:OpenId:ClientId"];
                options.Authority = configuration["Authentication:OpenId:Authority"];
                options.SignedOutRedirectUri = configuration["App:WebSiteRootAddress"] + "Account/Logout";
                options.ResponseType = OpenIdConnectResponseType.IdToken;

                options.MetadataAddress = "https://mytenant.b2clogin.com/mytenant.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=b2c_1_login";

                options.GetClaimsFromUserInfoEndpoint = true;
                options.ClaimActions.MapAll();

                var clientSecret = configuration["Authentication:OpenId:ClientSecret"];
                if (!clientSecret.IsNullOrEmpty())
                {
                    options.ClientSecret = clientSecret;
                }

                options.Events = new OpenIdConnectEvents()
                {

                    OnTokenValidated = (context) =>
                    {

                        var email = context.Principal.FindFirstValue("emails"); //initial test:emails => email first when multiple emails
                        ClaimsIdentity claimsId = context.Principal.Identity as ClaimsIdentity;
                        claimsId?.AddClaim(new Claim(ClaimTypes.NameIdentifier, $@"{email}"));

                        return Task.FromResult(0);
                    }
                };
            });
        }

I just don't understand what I'm missing / doing wrong. How did you configure you Azure AD B2C "return url"? Any hints are appreciated, i know there MUST be a way to get this to work, since you guys already managed to.

Thanks in advance

I'm trying to enable Azure B2C login for our application.

The aspnetzero version i'm using is:

  • aspnetcore + angular 7, v6.9

I've followed the instructions in this post (https://support.aspnetzero.com/QA/Questions/6525) and modified the authConfigurer accordingly.

The problem I'm running into is that I'm having trouble setting the LoginUrl for appsettings.json. I've tried several variants of LoginUrl, but I didnt get any to work.

I'd like the user to be taken to this page: https://mytenant.b2clogin.com/mytenant.onmicrosoft.com/b2c_1_signAndLogin/oauth2/v2.0/authorize?client_id=xxx&redirect_uri=https://localhost:4200/signin-oidc&response_type=id_token&scope=openid%20profile&response_mode=form_post so existing users can login and new users can signup.

But when i use the above link (which does what we need the login / signin flow to do) as "LoginUrl" it doesn't work, because the auth node_module adds its own parameters, which lead to an error when opening the link.

Aspnetzero support suggested using this as loginUrl: https://login.microsoftonline.com/94305afd-972f-4b71-810f-15bd41ab235e/oauth2/authorize But when I use this, the user is directly taken to a login form, without any possibility to create a new profile, which is crucial for our project.

Did anyone deal with a similar use-case and could provide some help / hint on this?

Thank you very much in advance.

Hi Richard, thank you very much for your help!

thank you very much for your quick response!

I've re-implemented the above code from scratch, but, like the first time i've tried to, i'm running into errors in importing classes.

So i have a few questions:

  • did you replace the other code, leaving only the "if" statement you posted?
  • Could you please share your "using" statements?
  • which version are you using? (i'm running the asp.core & angular, v 6.9.1 with .NET core 2.2)

thank you

Hello,

I'm also trying to authenticate on aspnetzero with B2C. I've inserted the "if (bool.Parse(configuration["Authentication:OpenId:IsEnabled"]))" part in the AuthConfigurer, but it's not working. I still have some doubts about the correct configuration in appsettings.json. Could you give me some hints about it?

I've tried different variants, but i just don't seem to get the right one..

"OpenId": { "IsEnabled": "true", "ClientId": "azure-id-hash", "Authority": "http://mytenant.onmicrosoft.com/", "LoginUrl": "http://localhost:4200/B2C_1_login", "ValidateIssuer": "true" },

What am I doing wrong? Am i missing something?
Any help is appreciated, thank you very much in advance.

Answer

with the breakpoint i've been able to fugure out the problem. Thank you very much for your help!

Answer

Sure!! This is the complete log:


An unhandled exception occurred while processing the request. UserFriendlyException: Login failed! RvsPortalMergedDemo.Web.Controllers.UiController.GetLoginResultAsync(string usernameOrEmailAddress, string password, string tenancyName) in UiController.cs, line 119


Abp.UI.UserFriendlyException: Login failed! at RvsPortalMergedDemo.Web.Controllers.UiController.GetLoginResultAsync(String usernameOrEmailAddress, String password, String tenancyName) in C:\Users\upalv\projects\aspnetzero\demo\RvsPortalMergedDemo\RvsPortalMergedDemo\src\RvsPortalMergedDemo.Web.Host\Controllers\UiController.cs:line 119 at RvsPortalMergedDemo.Web.Controllers.UiController.Login(LoginModel model) in C:\Users\upalv\projects\aspnetzero\demo\RvsPortalMergedDemo\RvsPortalMergedDemo\src\RvsPortalMergedDemo.Web.Host\Controllers\UiController.cs:line 86 at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.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() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at RvsPortalMergedDemo.Web.Startup.Startup.<>c.<<Configure>b__5_1>d.MoveNext() in C:\Users\upalv\projects\aspnetzero\demo\RvsPortalMergedDemo\RvsPortalMergedDemo\src\RvsPortalMergedDemo.Web.Host\Startup\Startup.cs:line 173 --- End of stack trace from previous location where exception was thrown --- at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Question

Good morning,

I'm currently setting up my project, following these instructions: https://docs.aspnetzero.com/documents/aspnet-core-angular/latest/Getting-Started-Angular-Merged

I've created the db, run the project and went to the login mask. As Tenant name I use "Default", with the default admin user login data, provided in the code / demo db.

But as I try to login I'm getting an error:

  • xPortalMergedDemo.Web.Controllers.UiController.GetLoginResultAsync(string usernameOrEmailAddress, string password, string tenancyName) in UiController.cs throw _abpLoginResultTypeHelper.CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress, tenancyName);

  • xPortalMergedDemo.Web.Controllers.UiController.Login(LoginModel model) in UiController.cs var loginResult = await GetLoginResultAsync(model.UserNameOrEmailAddress, model.Password, model.TenancyName); Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)

What am I missing here? Any hint is appreciated!!!

Thanks very much in advance, Kind regards Vicky Pallaoro

Showing 1 to 9 of 9 entries