-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1703 from haacked/comment-3f539b07
Comment by DaN on external-claims
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
id: 3f539b07 | ||
date: 2024-01-19T23:26:21.8691734Z | ||
name: DaN | ||
avatar: https://secure.gravatar.com/avatar/2523ef835f2b054a1d6291bf5f66e688?s=80&d=identicon&r=pg | ||
message: >+ | ||
I have implemented IUserClaimsPrincipalFactory and it seems that there is no need to inject SignInManager. | ||
public async override Task<ClaimsPrincipal> CreateAsync(User user) | ||
{ | ||
var principal = await base.CreateAsync(user); | ||
if (principal.Identity is ClaimsIdentity claimsIdentity) | ||
{ | ||
var httpContext = _httpContextAccessor.HttpContext; | ||
if (httpContext != null) | ||
{ | ||
var auth = await httpContext.AuthenticateAsync(IdentityConstants.ExternalScheme); | ||
var authClaims = auth.Principal?.Claims; | ||
if (authClaims != null) | ||
{ | ||
claimsIdentity.AddClaims(authClaims); | ||
} | ||
} | ||
} | ||
return principal; | ||
} | ||