-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor template to move DataModels to ServiceInterface + use Custom…
…UserSession
- Loading branch information
Showing
13 changed files
with
78 additions
and
72 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
File renamed without changes.
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,42 @@ | ||
using System.Security.Claims; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.Options; | ||
using ServiceStack; | ||
using ServiceStack.Web; | ||
|
||
namespace MyApp.Data; | ||
|
||
public class CustomUserSession : AuthUserSession | ||
{ | ||
public override void PopulateFromClaims(IRequest httpReq, ClaimsPrincipal principal) | ||
{ | ||
// Populate Session with data from Identity Auth Claims | ||
ProfileUrl = principal.FindFirstValue(JwtClaimTypes.Picture); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Add additional claims to the Identity Auth Cookie | ||
/// </summary> | ||
public class AdditionalUserClaimsPrincipalFactory( | ||
UserManager<ApplicationUser> userManager, | ||
RoleManager<IdentityRole> roleManager, | ||
IOptions<IdentityOptions> optionsAccessor) | ||
: UserClaimsPrincipalFactory<ApplicationUser,IdentityRole>(userManager, roleManager, optionsAccessor) | ||
{ | ||
public override async Task<ClaimsPrincipal> CreateAsync(ApplicationUser user) | ||
{ | ||
var principal = await base.CreateAsync(user); | ||
var identity = (ClaimsIdentity)principal.Identity!; | ||
|
||
var claims = new List<Claim>(); | ||
// Add additional claims here | ||
if (user.ProfileUrl != null) | ||
{ | ||
claims.Add(new Claim(JwtClaimTypes.Picture, user.ProfileUrl)); | ||
} | ||
|
||
identity.AddClaims(claims); | ||
return principal; | ||
} | ||
} |
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
"Name": "Lucy Bates", | ||
"Email": "[email protected]", | ||
"Bio": "Works in software design, company building, and the aerospace industry.", | ||
"ProfileUrl": "img/authors/author1.svg", | ||
"ProfileUrl": "img/profiles/user1.svg", | ||
"TwitterUrl": "https://twitter.com/lucy", | ||
"ThreadsUrl": "https://threads.net/@lucy", | ||
"GitHubUrl": "https://github.com/lucy" | ||
|
@@ -38,15 +38,15 @@ | |
"Name": "Gayle Smith", | ||
"Email": "[email protected]", | ||
"Bio": "Gayle is an author, consultant, and founder focusing on improving tech.", | ||
"ProfileUrl": "img/authors/author2.svg", | ||
"ProfileUrl": "img/profiles/user2.svg", | ||
"TwitterUrl": "https://twitter.com/gayle", | ||
"MastodonUrl": "https://mastodon.social/@gayle" | ||
}, | ||
{ | ||
"Name": "Brandon Foley", | ||
"Email": "[email protected]", | ||
"Bio": "I am a programmer at heart. I like to tinker with code and build generic coding structures.", | ||
"ProfileUrl": "img/authors/author3.svg", | ||
"ProfileUrl": "img/profiles/user3.svg", | ||
"GitHubUrl": "https://github.com/brandon" | ||
} | ||
] | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes