Skip to content

Commit dfc94fa

Browse files
authored
feat: auth sdk add impersonate login (#708)
* feat: Add GetThirdPartyUserByUserIdAsync * feat: add grantType * reactor: Support Environment * reactor: Remove GrantType.PSSO_PHONE_CODE * feat: auth sdk add impersonate login
1 parent 60d9a93 commit dfc94fa

File tree

10 files changed

+89
-0
lines changed

10 files changed

+89
-0
lines changed

src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static class GrantType
3535
[Description("Ldap")]
3636
public const string LDAP = "ldap";
3737

38+
[Description("Impersonation")]
39+
public const string IMPERSONATION = "impersonation";
40+
3841
private static readonly List<(string, string)> _disallowCombinations = new List<(string, string)>
3942
{
4043
(IMPLICIT, AUTHORIZATION_CODE),

src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantTypes.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ public class GrantTypes
4040

4141
public static ICollection<string> DeviceFlow =>
4242
new[] { GrantType.DEVICE_FLOW };
43+
44+
public static ICollection<string> Impersonation =>
45+
new[] { GrantType.IMPERSONATION };
4346
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
5+
6+
public class GetImpersonateInputModel : IEnvironmentModel
7+
{
8+
public string ImpersonationToken { get; set; } = "";
9+
10+
public string Environment { get; set; }
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
5+
6+
public class GetImpersonateOutputModel
7+
{
8+
public Guid ImpersonatorUserId { get; set; }
9+
10+
public Guid TargetUserId { get; set; }
11+
12+
public bool IsBackToImpersonator { get; set; }
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
5+
6+
public class GetThirdPartyUserByUserIdModel : IEnvironmentModel
7+
{
8+
public string Scheme { get; set; }
9+
10+
public Guid UserId { get; set; }
11+
12+
public string Environment { get; set; }
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
5+
6+
public class ImpersonateInputModel : IEnvironmentModel
7+
{
8+
public Guid UserId { get; set; }
9+
10+
public string Environment { get; set; }
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) MASA Stack All rights reserved.
2+
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3+
4+
namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;
5+
6+
public class ImpersonateOutputModel
7+
{
8+
public string ImpersonationToken { get; set; } = string.Empty;
9+
}

src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UserModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class UserModel
5050

5151
public string RealDisplayName => StaffDisplayName.IsNullOrEmpty() ? DisplayName : StaffDisplayName;
5252

53+
public Dictionary<string, string> ClaimData { get; set; } = new();
54+
5355
public UserModel()
5456
{
5557
Avatar = "";

src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public interface IUserService
2929

3030
Task<UserModel?> GetThirdPartyUserAsync(GetThirdPartyUserModel model);
3131

32+
Task<UserModel?> GetThirdPartyUserByUserIdAsync(GetThirdPartyUserByUserIdModel model);
33+
3234
Task<UserModel> UpsertAsync(UpsertUserModel user);
3335

3436
Task<UserModel?> ValidateAccountAsync(ValidateAccountModel validateAccountModel);
@@ -114,5 +116,9 @@ public interface IUserService
114116
Task<Dictionary<string, string>> GetClaimValuesAsync(Guid userId);
115117

116118
Task AddClaimValuesAsync(UserClaimValuesModel userClaimValuesModel);
119+
120+
Task<GetImpersonateOutputModel> GetImpersonateAsync(GetImpersonateInputModel model);
121+
122+
Task<ImpersonateOutputModel> ImpersonateAsync(ImpersonateInputModel model);
117123
}
118124

src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ public async Task<UserModel> AddThirdPartyUserAsync(AddThirdPartyUserModel user,
273273
return await _caller.GetAsync<GetThirdPartyUserModel, UserModel>(requestUri, model);
274274
}
275275

276+
public async Task<UserModel?> GetThirdPartyUserByUserIdAsync(GetThirdPartyUserByUserIdModel model)
277+
{
278+
var requestUri = $"api/thirdPartyUser/GetByUserId";
279+
return await _caller.GetAsync<GetThirdPartyUserByUserIdModel, UserModel>(requestUri, model);
280+
}
281+
276282
public async Task SetCurrentTeamAsync(Guid teamId)
277283
{
278284
var userId = _userContext.GetUserId<Guid>();
@@ -393,5 +399,17 @@ public Task AddClaimValuesAsync(UserClaimValuesModel userClaimValuesModel)
393399
var requestUri = $"api/user/claim-values";
394400
return _caller.PostAsync(requestUri, userClaimValuesModel);
395401
}
402+
403+
public async Task<GetImpersonateOutputModel> GetImpersonateAsync(GetImpersonateInputModel model)
404+
{
405+
var requestUri = $"api/user/impersonate";
406+
return await _caller.GetAsync<object, GetImpersonateOutputModel>(requestUri, model) ?? new();
407+
}
408+
409+
public async Task<ImpersonateOutputModel> ImpersonateAsync(ImpersonateInputModel model)
410+
{
411+
var requestUri = $"api/user/impersonate";
412+
return await _caller.PostAsync<object, ImpersonateOutputModel>(requestUri, model) ?? new();
413+
}
396414
}
397415

0 commit comments

Comments
 (0)