Open Closed

Issue while Passwordless Login #1857


User avatar
0
viswajwalith created
  • 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)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    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?

  • User Avatar
    0
    viswajwalith created

    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

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Did you define claims for the user that try to login passwordless, like here? These claims are required for user and role specific permissions.

  • User Avatar
    0
    viswajwalith created

    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

  • User Avatar
    0
    viswajwalith created

    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

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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("/");
            }
        }
    }
    
    
  • User Avatar
    0
    viswajwalith created

    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.Task1[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, IEnumerable1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action1 next) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Builder.RegistrationBuilder3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action1 next) at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 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, Action1 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, IEnumerable1 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.RequestHandlerMiddleware1.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

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    We have created new controller called passwordless2

    Please share code of passwordless2

  • User Avatar
    0
    viswajwalith created

    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("/");
            }
        }
    }
    ``
    
  • User Avatar
    0
    viswajwalith created

    SignInManager

    It seems the problem is with initiation of SignInManager

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Can you try to depend of AbpIdentityAspNetCoreModule?

  • User Avatar
    0
    viswajwalith created

    Can you try to depend of AbpIdentityAspNetCoreModule?

    I tried but not sure is it what you mean to say. because SignInAsync is not part of that

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
    [DependsOn(typeof(AbpIdentityAspNetCoreModule))]
    public class YourWebModule : AbpModule
    
  • User Avatar
    0
    viswajwalith created

    [DependsOn(typeof(AbpIdentityAspNetCoreModule))]

    Thanks for the quick turnaround. I already included cs file

    but SignInAsync is not found

    Am I missing anything?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    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

  • User Avatar
    0
    viswajwalith created

    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.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Good luck.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11