- ABP Framework version: v4.2.X
- UI type: MVC
- DB provider: EF Core / MongoDB
- Tiered (MVC) or Identity Server Separated (Angular): yes / no
- Exception message and stack trace:
- Steps to reproduce the issue:"
Hello, We are trying to implement passwordless sign-in refer to this link (https://github.com/abpframework/abp-samples/tree/master/PasswordlessAuthentication). On Successful sign and redirect to the home page page, we are unable to see our application menus it seems some permission issues. Can you help us lettig us know if we missed any? Do we suppose to do any kind of callback after sign-in Do we suppose to add any extra claim to this login portion of code (https://github.com/abpframework/abp-samples/blob/master/PasswordlessAuthentication/src/PasswordlessAuthentication.Web/Controllers/PasswordlessController.cs)
17 Answer(s)
-
0
Hi @viswajwalith, there is a community article about passwordless authentication, you can read from here. Can you check it and ensure there are not any steps that you missed?
Hi we already followed that but that is for Application Template, when we implemented the same in Micro service template facing the above issue mentioned
-
0
Did you define claims for the user that try to login passwordless, like here? These claims are required for user and role specific permissions.
Yes we did but still will cross verify and get back to you
-
0
Did you define claims for the user that try to login passwordless, like here?
These claims are required for user and role specific permissions.Yes we did but still will cross verify and get back to you
This is what we had in out code
after login, I kept the display of claims in home page
You can see role is coming as admin.
Our actual menu will look like something below
-
0
hi
https://github.com/abpframework/abp-samples/pull/103
using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Identity; using Volo.Abp.Identity.AspNetCore; namespace PasswordlessAuthentication.Web.Controllers { public class PasswordlessController : AbpController { protected IdentityUserManager UserManager { get; } protected AbpSignInManager SignInManager { get; } public PasswordlessController(IdentityUserManager userManager, AbpSignInManager signInManager) { UserManager = userManager; SignInManager = signInManager; } public virtual async Task<IActionResult> Login(string token, string userId) { var user = await UserManager.FindByIdAsync(userId); var isValid = await UserManager.VerifyUserTokenAsync(user, "PasswordlessLoginProvider", "passwordless-auth", token); if (!isValid) { throw new UnauthorizedAccessException("The token " + token + " is not valid for the user " + userId); } await UserManager.UpdateSecurityStampAsync(user); await SignInManager.SignInAsync(user, isPersistent: false); return Redirect("/"); } } }
-
0
We have created new controller called passwordless2 and tried ur code, but getting the below error. are we missing anything?
Error Log: 2021-09-16 13:19:50.105 +00:00 [INF] Request starting HTTP/2 GET https://localhost:44321/Passwordless2/Login?token=727076&userId=bc89cb04-d25d-651e-9417-39fcb9258fd3 - - 2021-09-16 13:19:50.121 +00:00 [INF] Executing endpoint 'Passwordless2Authentication.Web.Controllers.Passwordless2Controller.Login (Exceego.EHSWatch.AppV3.Web)' 2021-09-16 13:19:50.121 +00:00 [INF] Route matched with {action = "Login", controller = "Passwordless2", area = "", page = ""}. Executing controller action with signature System.Threading.Tasks.Task
1[Microsoft.AspNetCore.Mvc.IActionResult] Login(System.String, System.String) on controller Passwordless2Authentication.Web.Controllers.Passwordless2Controller (Exceego.EHSWatch.AppV3.Web). 2021-09-16 13:19:50.125 +00:00 [INF] Executed action Passwordless2Authentication.Web.Controllers.Passwordless2Controller.Login (Exceego.EHSWatch.AppV3.Web) in 4.0034ms 2021-09-16 13:19:50.126 +00:00 [INF] Executed endpoint 'Passwordless2Authentication.Web.Controllers.Passwordless2Controller.Login (Exceego.EHSWatch.AppV3.Web)' 2021-09-16 13:19:50.130 +00:00 [ERR] An unhandled exception has occurred while executing the request. Autofac.Core.DependencyResolutionException: An exception was thrown while activating Passwordless2Authentication.Web.Controllers.Passwordless2Controller. ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Volo.Abp.Autofac.AbpAutofacConstructorFinder' on type 'Passwordless2Authentication.Web.Controllers.Passwordless2Controller' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.Identity.AspNetCore.AbpSignInManager signInManager' of constructor 'Void .ctor(Volo.Abp.Identity.IdentityUserManager, Volo.Abp.Identity.AspNetCore.AbpSignInManager)'. at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable
1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action
1 next) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Builder.RegistrationBuilder
3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action1 next) at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action
1 next) --- End of inner exception stack trace --- at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action
1 next) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable
1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context) at Elsa.Activities.Http.Middleware.RequestHandlerMiddleware
1.InvokeAsync(HttpContext httpContext, THandler handler) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext() --- End of stack trace from previous location --- at Volo.Abp.AspNetCore.MultiTenancy.MultiTenancyMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Prometheus.HttpMetrics.HttpRequestDurationMiddleware.Invoke(HttpContext context) at Prometheus.HttpMetrics.HttpRequestCountMiddleware.Invoke(HttpContext context) at Prometheus.HttpMetrics.HttpInProgressMiddleware.Invoke(HttpContext context) at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context) 2021-09-16 13:19:50.139 +00:00 [INF] Request finished HTTP/2 GET https://localhost:44321/Passwordless2/Login?token=727076&userId=bc89cb04-d25d-651e-9417-39fcb9258fd3 - - - 500 - text/html;+charset=utf-8 33.7823ms -
0
We have created new controller called passwordless2
Please share code of
passwordless2
-
0
We have created new controller called passwordless2
Please share code of
passwordless2
using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Identity; using Volo.Abp.Identity.AspNetCore; namespace Passwordless2Authentication.Web.Controllers { public class Passwordless2Controller : AbpController { protected IdentityUserManager UserManager { get; } protected AbpSignInManager SignInManager { get; } public Passwordless2Controller(IdentityUserManager userManager, AbpSignInManager signInManager) { UserManager = userManager; SignInManager = signInManager; } public virtual async Task<IActionResult> Login(string token, string userId) { var user = await UserManager.FindByIdAsync(userId); var isValid = await UserManager.VerifyUserTokenAsync(user, "PasswordlessLoginProvider", "passwordless-auth", token); if (!isValid) { throw new UnauthorizedAccessException("The token " + token + " is not valid for the user " + userId); } await UserManager.UpdateSecurityStampAsync(user); await SignInManager.SignInAsync(user, isPersistent: false); return Redirect("/"); } } } ``
-
0
SignInManager
It seems the problem is with initiation of SignInManager
-
0
Can you try to depend of
AbpIdentityAspNetCoreModule
? -
0
-
0
[DependsOn(typeof(AbpIdentityAspNetCoreModule))] public class YourWebModule : AbpModule
-
0
-
0
-
0
hi
You need to use
AbpSignInManager
.protected AbpSignInManager SignInManager { get; }
https://support.abp.io/QA/Questions/1857?_se=bGltaW5nLm1hQHZvbG9zb2Z0LmNvbQ==#answer-071a4ee5-b305-e512-b1bf-39ff002b2c16
This resolved the errors, but it is redirecting to login page. I will check and update you.
-
0
Good luck.