Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auth sdk add impersonate login #708

Merged
merged 5 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public static class GrantType
[Description("Ldap")]
public const string LDAP = "ldap";

[Description("Impersonation")]
public const string IMPERSONATION = "impersonation";

private static readonly List<(string, string)> _disallowCombinations = new List<(string, string)>
{
(IMPLICIT, AUTHORIZATION_CODE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ public class GrantTypes

public static ICollection<string> DeviceFlow =>
new[] { GrantType.DEVICE_FLOW };

public static ICollection<string> Impersonation =>
new[] { GrantType.IMPERSONATION };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class GetImpersonateInputModel : IEnvironmentModel
{
public string ImpersonationToken { get; set; } = "";

public string Environment { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class GetImpersonateOutputModel
{
public Guid ImpersonatorUserId { get; set; }

public Guid TargetUserId { get; set; }

public bool IsBackToImpersonator { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class GetThirdPartyUserByUserIdModel : IEnvironmentModel
{
public string Scheme { get; set; }

public Guid UserId { get; set; }

public string Environment { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class ImpersonateInputModel : IEnvironmentModel
{
public Guid UserId { get; set; }

public string Environment { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model;

public class ImpersonateOutputModel
{
public string ImpersonationToken { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class UserModel

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

public Dictionary<string, string> ClaimData { get; set; } = new();

public UserModel()
{
Avatar = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface IUserService

Task<UserModel?> GetThirdPartyUserAsync(GetThirdPartyUserModel model);

Task<UserModel?> GetThirdPartyUserByUserIdAsync(GetThirdPartyUserByUserIdModel model);

Task<UserModel> UpsertAsync(UpsertUserModel user);

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

Task AddClaimValuesAsync(UserClaimValuesModel userClaimValuesModel);

Task<GetImpersonateOutputModel> GetImpersonateAsync(GetImpersonateInputModel model);

Task<ImpersonateOutputModel> ImpersonateAsync(ImpersonateInputModel model);
}

Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ public async Task<UserModel> AddThirdPartyUserAsync(AddThirdPartyUserModel user,
return await _caller.GetAsync<GetThirdPartyUserModel, UserModel>(requestUri, model);
}

public async Task<UserModel?> GetThirdPartyUserByUserIdAsync(GetThirdPartyUserByUserIdModel model)
{
var requestUri = $"api/thirdPartyUser/GetByUserId";
return await _caller.GetAsync<GetThirdPartyUserByUserIdModel, UserModel>(requestUri, model);
}

public async Task SetCurrentTeamAsync(Guid teamId)
{
var userId = _userContext.GetUserId<Guid>();
Expand Down Expand Up @@ -393,5 +399,17 @@ public Task AddClaimValuesAsync(UserClaimValuesModel userClaimValuesModel)
var requestUri = $"api/user/claim-values";
return _caller.PostAsync(requestUri, userClaimValuesModel);
}

public async Task<GetImpersonateOutputModel> GetImpersonateAsync(GetImpersonateInputModel model)
{
var requestUri = $"api/user/impersonate";
return await _caller.GetAsync<object, GetImpersonateOutputModel>(requestUri, model) ?? new();
}

public async Task<ImpersonateOutputModel> ImpersonateAsync(ImpersonateInputModel model)
{
var requestUri = $"api/user/impersonate";
return await _caller.PostAsync<object, ImpersonateOutputModel>(requestUri, model) ?? new();
}
}

Loading