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
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:
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.
with the breakpoint i've been able to fugure out the problem. Thank you very much for your help!
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)