Skip to content

Commit e8730fd

Browse files
committed
Merge IRequireClaimsPrincipal with IAuthSessionExtended and AuthUserSession
1 parent b152502 commit e8730fd

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎ServiceStack/src/ServiceStack.Common/AppTasks.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void Register(string taskName, Action<string[]> appTask)
9090
var appTask = appTaskWithArgs.LeftPart(':');
9191
var args = appTaskWithArgs.IndexOf(':') >= 0
9292
? appTaskWithArgs.RightPart(':').Split(',')
93-
: Array.Empty<string>();
93+
: [];
9494

9595
if (!tasks.TryGetValue(appTask, out var taskFn))
9696
{

‎ServiceStack/src/ServiceStack.Extensions/Auth/IdentityAuth.cs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static Action<IServiceCollection,AuthFeature> For<TUser,TKey>(Action<Iden
4343
where TUser : IdentityUser<TKey>, new()
4444
{
4545
var ctx = new IdentityAuthContext<TUser, TKey>(
46-
() => new IdentityAuthSession(new ClaimsPrincipal()),
46+
() => new AuthUserSession(),
4747
new IdentityApplicationAuthProvider<TUser, TKey>(),
4848
new IdentityCredentialsAuthProvider<TUser, TKey>(),
4949
new IdentityJwtAuthProvider<TUser, TKey>(),
@@ -638,13 +638,5 @@ public async Task<IList<Claim>> GetClaimsAsync(Func<UserManager<TUser>, Task<ILi
638638
}
639639
}
640640

641-
public interface IRequireClaimsPrincipal
642-
{
643-
ClaimsPrincipal User { get; set; }
644-
}
645641

646-
public class IdentityAuthSession(ClaimsPrincipal user) : AuthUserSession, IRequireClaimsPrincipal
647-
{
648-
[IgnoreDataMember] public ClaimsPrincipal User { get; set; } = user;
649-
}
650642

‎ServiceStack/src/ServiceStack/Auth/IAuthSession.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Security.Claims;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using ServiceStack.Text;
@@ -70,7 +71,12 @@ public interface IAuthSession : IRuntimeSerializable
7071
HashSet<string> GetUserAttributes(IRequest request);
7172
}
7273

73-
public interface IAuthSessionExtended : IAuthSession
74+
public interface IRequireClaimsPrincipal
75+
{
76+
ClaimsPrincipal User { get; set; }
77+
}
78+
79+
public interface IAuthSessionExtended : IAuthSession, IRequireClaimsPrincipal
7480
{
7581
string Company { get; set; }
7682
string PrimaryEmail { get; set; }
@@ -105,6 +111,7 @@ public interface IAuthSessionExtended : IAuthSession
105111
string RecoveryToken { get; set; }
106112
int? RefId { get; set; }
107113
string RefIdStr { get; set; }
114+
ClaimsPrincipal User { get; set; }
108115

109116
/// <summary>
110117
/// High-level overridable API that ServiceStack uses to check whether a user has all requiredRoles.

‎ServiceStack/src/ServiceStack/AuthUserSession.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public AuthUserSession()
9090
[DataMember(Order = 59)] public virtual string RecoveryToken { get; set; }
9191
[DataMember(Order = 60)] public virtual int? RefId { get; set; }
9292
[DataMember(Order = 61)] public virtual string RefIdStr { get; set; }
93+
[DataMember(Order = 62)] public ClaimsPrincipal User { get; set; } = new();
9394

9495
public virtual bool IsAuthorized(string provider)
9596
{

0 commit comments

Comments
 (0)