From 55509a0d8cb3fcc11062c8f70cfdec333fb95d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 23 Aug 2019 17:32:44 +0300 Subject: [PATCH] Revisit GetAdditionalClaimsOrNull method of AbpResourceOwnerPasswordValidator --- .../AbpResourceOwnerPasswordValidator.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index 946813aff8..7c46fbd1ea 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -53,7 +53,15 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity _logger.LogInformation("Credentials validated for username: {username}", context.UserName); await _events.RaiseAsync(new UserLoginSuccessEvent(context.UserName, sub, context.UserName, interactive: false)); - context.Result = new GrantValidationResult(sub, OidcConstants.AuthenticationMethods.Password, GetAdditionalClaimsOrNull(user)); + var additionalClaims = new List(); + + await AddCustomClaimsAsync(additionalClaims, user, context); + + context.Result = new GrantValidationResult( + sub, + OidcConstants.AuthenticationMethods.Password, + additionalClaims.ToArray() + ); return; } @@ -82,14 +90,14 @@ namespace Volo.Abp.IdentityServer.AspNetIdentity context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant); } - protected virtual IEnumerable GetAdditionalClaimsOrNull(IdentityUser user) + protected virtual Task AddCustomClaimsAsync(List customClaims, IdentityUser user, ResourceOwnerPasswordValidationContext context) { - if (!user.TenantId.HasValue) + if (user.TenantId.HasValue) { - return null; + customClaims.Add(new Claim(AbpClaimTypes.TenantId, user.TenantId?.ToString())); } - return new[] { new Claim(AbpClaimTypes.TenantId, user.TenantId?.ToString()) }; + return Task.CompletedTask; } } }