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

⚡ refactor: LdapGrantValidator add doaminName Claim #1340

Merged
merged 1 commit into from
Aug 2, 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
13 changes: 13 additions & 0 deletions src/Web/Masa.Auth.Web.Sso/Infrastructure/Consts/ClaimTypeConsts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.Web.Sso.Infrastructure.Consts;

public static class ClaimTypeConsts
{
public const string IMPERSONATOR_USER_ID = $"{DEFAULT_PREFIX}/impersonatorUserId";

public const string DOMAIN_NAME = $"{DEFAULT_PREFIX}/domainName";

private const string DEFAULT_PREFIX = "https://masastack.com/security/identity/claims";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class ImpersonationGrantValidator : IExtensionGrantValidator
IAuthClient _authClient;
public string GrantType { get; } = BuildingBlocks.Authentication.OpenIdConnect.Models.Constans.GrantType.IMPERSONATION;

const string IMPERSONATOR_USER_ID = "https://masastack.com/security/identity/claims/impersonatorUserId";

public ImpersonationGrantValidator(IAuthClient authClient)
{
_authClient = authClient;
Expand Down Expand Up @@ -54,7 +52,7 @@ public async Task ValidateAsync(ExtensionGrantValidationContext context)

if (!cacheItem.IsBackToImpersonator)
{
claims.Add(new Claim(IMPERSONATOR_USER_ID, cacheItem.ImpersonatorUserId.ToString()));
claims.Add(new Claim(ClaimTypeConsts.IMPERSONATOR_USER_ID, cacheItem.ImpersonatorUserId.ToString()));
}

context.Result = new GrantValidationResult(cacheItem.TargetUserId.ToString(), "impersonation", claims);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public async Task ValidateAsync(ExtensionGrantValidationContext context)
});
}

context.Result = new GrantValidationResult(authUser.Id.ToString(), "ldap");
var claims = new List<Claim>
{
new Claim(ClaimTypeConsts.DOMAIN_NAME, ldapUser.SamAccountName)
};

context.Result = new GrantValidationResult(authUser.Id.ToString(), "ldap", claims);
}
catch (Exception ex)
{
Expand Down
1 change: 1 addition & 0 deletions src/Web/Masa.Auth.Web.Sso/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
global using Masa.Auth.Web.Sso.Infrastructure;
global using Masa.Auth.Web.Sso.Infrastructure.Aliyun;
global using Masa.Auth.Web.Sso.Infrastructure.Attributes;
global using Masa.Auth.Web.Sso.Infrastructure.Consts;
global using Masa.Auth.Web.Sso.Infrastructure.Events;
global using Masa.Auth.Web.Sso.Infrastructure.Options;
global using Masa.Auth.Web.Sso.Infrastructure.Services;
Expand Down