committed by
GitHub
19 changed files with 261 additions and 14 deletions
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -0,0 +1,19 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net7.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.OpenIddict.AspNetCore" Version="$(VoloAbpPackageVersion)" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\identity\LINGYUN.Abp.Identity.Domain.Shared\LINGYUN.Abp.Identity.Domain.Shared.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,20 @@ |
|||
using LINGYUN.Abp.Identity; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
using VoloAbpOpenIddictAspNetCoreModule = Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule; |
|||
|
|||
namespace LINGYUN.Abp.OpenIddict.AspNetCore; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpIdentityDomainSharedModule), |
|||
typeof(VoloAbpOpenIddictAspNetCoreModule))] |
|||
public class AbpOpenIddictAspNetCoreModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
PreConfigure<OpenIddictServerBuilder>(builder => |
|||
{ |
|||
builder.RegisterClaims(new[] { IdentityConsts.ClaimType.Avatar.Name } ); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
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)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,68 @@ |
|||
using LINGYUN.Abp.Identity; |
|||
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; |
|||
using VoloUserInfoController = Volo.Abp.OpenIddict.Controllers.UserInfoController; |
|||
|
|||
namespace LINGYUN.Abp.OpenIddict.AspNetCore.Controllers; |
|||
|
|||
[ExposeServices( |
|||
typeof(VoloUserInfoController), |
|||
typeof(UserInfoController))] |
|||
public class UserInfoController : VoloUserInfoController |
|||
{ |
|||
protected async override Task<Dictionary<string, object>> GetUserInfoClaims() |
|||
{ |
|||
var user = await UserManager.GetUserAsync(User); |
|||
if (user == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
var claims = new Dictionary<string, object>(StringComparer.Ordinal) |
|||
{ |
|||
// Note: the "sub" claim is a mandatory claim and must be included in the JSON response.
|
|||
[OpenIddictConstants.Claims.Subject] = await UserManager.GetUserIdAsync(user) |
|||
}; |
|||
|
|||
if (User.HasScope(OpenIddictConstants.Scopes.Profile)) |
|||
{ |
|||
claims[AbpClaimTypes.TenantId] = user.TenantId; |
|||
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 == IdentityConsts.ClaimType.Avatar.Name); |
|||
if (picture != null) |
|||
{ |
|||
claims[OpenIddictConstants.Claims.Picture] = picture.ClaimValue; |
|||
} |
|||
} |
|||
|
|||
if (User.HasScope(OpenIddictConstants.Scopes.Email)) |
|||
{ |
|||
claims[OpenIddictConstants.Claims.Email] = await UserManager.GetEmailAsync(user); |
|||
claims[OpenIddictConstants.Claims.EmailVerified] = await UserManager.IsEmailConfirmedAsync(user); |
|||
} |
|||
|
|||
if (User.HasScope(OpenIddictConstants.Scopes.Phone)) |
|||
{ |
|||
claims[OpenIddictConstants.Claims.PhoneNumber] = await UserManager.GetPhoneNumberAsync(user); |
|||
claims[OpenIddictConstants.Claims.PhoneNumberVerified] = await UserManager.IsPhoneNumberConfirmedAsync(user); |
|||
} |
|||
|
|||
if (User.HasScope(OpenIddictConstants.Scopes.Roles)) |
|||
{ |
|||
claims[OpenIddictConstants.Claims.Role] = await UserManager.GetRolesAsync(user); |
|||
} |
|||
|
|||
// Note: the complete list of standard claims supported by the OpenID Connect specification
|
|||
// can be found here: http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
|
|||
|
|||
return claims; |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- |
|||
https://go.microsoft.com/fwlink/?LinkID=208121. |
|||
--> |
|||
<Project> |
|||
<PropertyGroup> |
|||
<DeleteExistingFiles>true</DeleteExistingFiles> |
|||
<ExcludeApp_Data>false</ExcludeApp_Data> |
|||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish> |
|||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> |
|||
<LastUsedPlatform>Any CPU</LastUsedPlatform> |
|||
<PublishProvider>FileSystem</PublishProvider> |
|||
<PublishUrl>bin\Release\net7.0\publish\</PublishUrl> |
|||
<WebPublishMethod>FileSystem</WebPublishMethod> |
|||
<_TargetId>Folder</_TargetId> |
|||
<SiteUrlToLaunchAfterPublish /> |
|||
<TargetFramework>net7.0</TargetFramework> |
|||
<ProjectGuid>83d2f8f2-82c7-4919-9b65-d0fbf0b5324c</ProjectGuid> |
|||
<SelfContained>false</SelfContained> |
|||
</PropertyGroup> |
|||
</Project> |
|||
@ -0,0 +1,11 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- |
|||
https://go.microsoft.com/fwlink/?LinkID=208121. |
|||
--> |
|||
<Project> |
|||
<PropertyGroup> |
|||
<_PublishTargetUrl>D:\C Sharp\Open-Sources\abp-next-admin\aspnet-core\services\LY.MicroService.Applications.Single\bin\Release\net7.0\publish\</_PublishTargetUrl> |
|||
<History>True|2023-10-28T08:18:57.7769358Z;True|2023-10-28T14:39:34.8714667+08:00;</History> |
|||
<LastFailureDetails /> |
|||
</PropertyGroup> |
|||
</Project> |
|||
Loading…
Reference in new issue