-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support impersonate login and thirdPartyUser claimData (#1271)
* feat: Add ThirdPartyUserClaim * chore: Dockerfile * feat: Add PssoPhoneNumberGrantValidator * refactor:GetProfileDataAsync Claim padding adjustment * feat: Add ImpersonationGrantValidator * feat: ImpersonatedNavigation * feat: PssoPhoneCodeGrantValidator * chore : Update package * feat: Add PssoService * reactor: Remove PSSO code * reactor: Adjusting Ldap Authenticate * chore: Update package * chore:Restore Dockerfile * style: global using * chore:Upgrade Package * style: Useless using * style: global using * refactor:Delete useless code and formatting
- Loading branch information
Showing
33 changed files
with
3,971 additions
and
66 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
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
9 changes: 9 additions & 0 deletions
9
src/Contracts/Masa.Auth.Contracts.Admin/Subjects/ImpersonateInput.cs
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,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Subjects; | ||
|
||
public class ImpersonateInput | ||
{ | ||
public Guid UserId { get; set; } | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Contracts/Masa.Auth.Contracts.Admin/Subjects/ImpersonateOutput.cs
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,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Contracts.Admin.Subjects; | ||
|
||
public class ImpersonateOutput | ||
{ | ||
public string ImpersonationToken { get; set; } = string.Empty; | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/Services/Masa.Auth.Service.Admin/Application/Subjects/Commands/ImpersonateUserCommand.cs
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,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Service.Admin.Application.Subjects.Commands; | ||
|
||
public record ImpersonateUserCommand(Guid UserId, bool IsBackToImpersonator) : Command | ||
{ | ||
public ImpersonateOutput Result { get; set; } = new(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Services/Masa.Auth.Service.Admin/Application/Subjects/Queries/ImpersonatedUserQuery.cs
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,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Service.Admin.Application.Subjects.Queries; | ||
|
||
public record ImpersonatedUserQuery(string ImpersonationToken) : Query<ImpersonationCacheItem> | ||
{ | ||
public override ImpersonationCacheItem Result { get; set; } = new(); | ||
} |
9 changes: 9 additions & 0 deletions
9
...vices/Masa.Auth.Service.Admin/Application/Subjects/Queries/ThirdPartyUserByUserIdQuery.cs
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,9 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Service.Admin.Application.Subjects.Queries; | ||
|
||
public record ThirdPartyUserByUserIdQuery(Guid UserId, Guid ThirdPartyIdpId) : Query<UserModel?> | ||
{ | ||
public override UserModel? Result { get; set; } | ||
} |
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
69 changes: 69 additions & 0 deletions
69
src/Services/Masa.Auth.Service.Admin/Domain/Subjects/Aggregates/PasswordType.cs
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,69 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Service.Admin.Domain.Subjects.Aggregates; | ||
|
||
public class PasswordType : Enumeration | ||
{ | ||
public static PasswordType Default = new PasswordType(); | ||
|
||
public static PasswordType MD5 = new MD5PasswordType(); | ||
|
||
public static PasswordType HashPassword = new HashPasswordType(); | ||
|
||
public PasswordType() : base(0, "") { } | ||
|
||
public PasswordType(int id, string name) : base(id, name) | ||
{ | ||
} | ||
|
||
public virtual string EncryptPassword(User user, string password) | ||
{ | ||
return MD5.EncryptPassword(user, password); | ||
} | ||
|
||
public virtual bool VerifyPassword(User user, string encryptPassword, string providedPassword) | ||
{ | ||
return MD5.VerifyPassword(user, encryptPassword, providedPassword); | ||
} | ||
|
||
public static PasswordType StartNew(string type) => type switch | ||
{ | ||
nameof(MD5) => new MD5PasswordType(), | ||
nameof(HashPassword) => new HashPasswordType(), | ||
_ => new PasswordType() | ||
}; | ||
|
||
private class MD5PasswordType : PasswordType | ||
{ | ||
public MD5PasswordType() : base(1, nameof(MD5)) { } | ||
|
||
public override string EncryptPassword(User user, string password) | ||
{ | ||
return MD5Utils.EncryptRepeat(password); | ||
} | ||
|
||
public override bool VerifyPassword(User user, string encryptPassword, string providedPassword) | ||
{ | ||
return encryptPassword == MD5Utils.EncryptRepeat(providedPassword ?? ""); | ||
} | ||
} | ||
|
||
private class HashPasswordType : PasswordType | ||
{ | ||
public HashPasswordType() : base(2, nameof(HashPassword)) { } | ||
|
||
public override string EncryptPassword(User user, string password) | ||
{ | ||
var hasher = new PasswordHasher<User>(); | ||
return hasher.HashPassword(user, password); | ||
} | ||
|
||
public override bool VerifyPassword(User user, string encryptPassword, string providedPassword) | ||
{ | ||
var hasher = new PasswordHasher<User>(); | ||
var result = hasher.VerifyHashedPassword(user, encryptPassword, providedPassword); | ||
return result != PasswordVerificationResult.Failed; | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/Services/Masa.Auth.Service.Admin/Infrastructure/CacheModels/ImpersonationCacheItem.cs
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,25 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Service.Admin.Infrastructure.CacheModels; | ||
|
||
[Serializable] | ||
public class ImpersonationCacheItem | ||
{ | ||
public Guid ImpersonatorUserId { get; set; } | ||
|
||
public Guid TargetUserId { get; set; } | ||
|
||
public bool IsBackToImpersonator { get; set; } | ||
|
||
public ImpersonationCacheItem() | ||
{ | ||
|
||
} | ||
|
||
public ImpersonationCacheItem(Guid targetUserId, bool isBackToImpersonator) | ||
{ | ||
TargetUserId = targetUserId; | ||
IsBackToImpersonator = isBackToImpersonator; | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/Services/Masa.Auth.Service.Admin/Infrastructure/ValueConverters/JsonValueConverter.cs
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,28 @@ | ||
// Copyright (c) MASA Stack All rights reserved. | ||
// Licensed under the Apache License. See LICENSE.txt in the project root for license information. | ||
|
||
namespace Masa.Auth.Service.Admin.Infrastructure.ValueConverters; | ||
|
||
public class JsonValueConverter<T> : ValueConverter<T, string> where T : class, new() | ||
{ | ||
public JsonValueConverter() | ||
: base(x => SerializeObject(x), x => DeserializeObject(x)) | ||
{ | ||
|
||
} | ||
|
||
private static string SerializeObject(T obj) | ||
{ | ||
return JsonSerializer.Serialize(obj); | ||
} | ||
|
||
private static T DeserializeObject(string json) | ||
{ | ||
if (string.IsNullOrEmpty(json)) | ||
{ | ||
return new T(); | ||
} | ||
|
||
return JsonSerializer.Deserialize<T>(json)!; | ||
} | ||
} |
Oops, something went wrong.