iminet

identityissue-accountcshtmlcs

Apr 1st, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1.  public async Task<IActionResult> OnGetLogin(string Id = "default")
  2.         {            
  3.             if (Enum.IsDefined(typeof(AuthProviders), Id))
  4.             {
  5.                 Console.WriteLine(Id);
  6.                 var resp = new ChallengeResult(Id,
  7.                 new AuthenticationProperties
  8.                 {            
  9.                     IsPersistent = true,
  10.                     AllowRefresh = true,
  11.                     RedirectUri = Url.Content("/Account/Response/"+Id),
  12.                 });
  13.  
  14.                 return resp;
  15.             }
  16.             else Console.WriteLine($"No Authentication provider exists with this name: {Id}");
  17.             return new RedirectResult("/Account");
  18.         }
  19.  
  20.  
  21. public async Task<IActionResult> OnGetResponse(string Id = "default")
  22.         {
  23.             var auth = await HttpContext.AuthenticateAsync(Id);
  24.             Message = $"{(auth.Succeeded == true ? "Sikeres" : "Sikertelen")} bejelentkezés ide: {Id} :: {auth.Principal.Identity.Name}";
  25.  
  26.             if (auth.Succeeded)
  27.             {
  28.                
  29.                 HttpContext.Session.SetString($"{Id}:access_token", Accessor?.HttpContext?.GetTokenAsync(Id, "access_token").Result);
  30.                 var claimsIdentity = new ClaimsIdentity(auth.Principal.Identity);
  31.                 var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
  32.             }
  33.             return new RedirectResult("/Account");
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment