Browse Source

feat(openiddict): 移除无用的头像标识

pull/1202/head
colin 9 months ago
parent
commit
775cb73b5a
  1. 9
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/AbpOpenIddictAspNetCoreModule.cs
  2. 12
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/AbpSessionOpenIddictClaimsPrincipalHandler.cs
  3. 33
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/AvatarUrlClaimsPrincipalContributor.cs
  4. 7
      aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/Controllers/UserInfoController.cs

9
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/AbpOpenIddictAspNetCoreModule.cs

@ -1,5 +1,4 @@
using LINGYUN.Abp.Identity;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
using VoloAbpOpenIddictAspNetCoreModule = Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule;
@ -8,13 +7,7 @@ namespace LINGYUN.Abp.OpenIddict.AspNetCore;
[DependsOn(
typeof(AbpIdentityDomainSharedModule),
typeof(VoloAbpOpenIddictAspNetCoreModule))]
[System.Obsolete("The module has been deprecated and will be removed in future versions")]
public class AbpOpenIddictAspNetCoreModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<OpenIddictServerBuilder>(builder =>
{
builder.RegisterClaims(new[] { IdentityConsts.ClaimType.Avatar.Name } );
});
}
}

12
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/AbpSessionOpenIddictClaimsPrincipalHandler.cs

@ -1,12 +0,0 @@
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.OpenIddict;
namespace LINGYUN.Abp.OpenIddict.AspNetCore;
public class AbpSessionOpenIddictClaimsPrincipalHandler : IAbpOpenIddictClaimsPrincipalHandler, ITransientDependency
{
public Task HandleAsync(AbpOpenIddictClaimsPrincipalHandlerContext context)
{
return Task.CompletedTask;
}
}

33
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/AvatarUrlClaimsPrincipalContributor.cs

@ -1,33 +0,0 @@
using LINGYUN.Abp.Identity;
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
using Volo.Abp.Security.Claims;
namespace LINGYUN.Abp.OpenIddict.AspNetCore;
public class AvatarUrlClaimsPrincipalContributor : IAbpClaimsPrincipalContributor, ITransientDependency
{
public async virtual Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
{
var identity = context.ClaimsPrincipal.Identities.FirstOrDefault();
if (identity != null)
{
if (identity.HasClaim(x => x.Type == IdentityConsts.ClaimType.Avatar.Name))
{
return;
}
var userManager = context.ServiceProvider.GetRequiredService<IdentityUserManager>();
var user = await userManager.GetUserAsync(context.ClaimsPrincipal);
var userClaims = await userManager.GetClaimsAsync(user);
var userAvatarUrl = userClaims.FirstOrDefault(x => x.Type == IdentityConsts.ClaimType.Avatar.Name);
if (userAvatarUrl != null)
{
identity.AddIfNotContains(new Claim(IdentityConsts.ClaimType.Avatar.Name, userAvatarUrl.Value));
}
}
}
}

7
aspnet-core/modules/openIddict/LINGYUN.Abp.OpenIddict.AspNetCore/LINGYUN/Abp/OpenIddict/AspNetCore/Controllers/UserInfoController.cs

@ -1,7 +1,6 @@
using OpenIddict.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
@ -36,12 +35,6 @@ public class UserInfoController : VoloUserInfoController
claims[OpenIddictConstants.Claims.PreferredUsername] = user.UserName;
claims[OpenIddictConstants.Claims.FamilyName] = user.Surname;
claims[OpenIddictConstants.Claims.GivenName] = user.Name;
// 重写添加用户头像
var picture = user.Claims.FirstOrDefault(x => x.ClaimType == AbpClaimTypes.Picture);
if (picture != null)
{
claims[OpenIddictConstants.Claims.Picture] = picture.ClaimValue;
}
}
if (User.HasScope(OpenIddictConstants.Scopes.Email))

Loading…
Cancel
Save