-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1129 from colinin/scan-code-login-openiddict
feat(openiddict): 增加扫码登录实现
- Loading branch information
Showing
36 changed files
with
1,025 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
.../account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/Models/GenerateQrCodeResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace LINGYUN.Abp.Account.Web.Areas.Account.Controllers.Models; | ||
|
||
public class GenerateQrCodeResult | ||
{ | ||
public string Key { get; set; } | ||
} |
9 changes: 9 additions & 0 deletions
9
...ules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/Models/QrCodeInfoResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using LINGYUN.Abp.Identity.QrCode; | ||
|
||
namespace LINGYUN.Abp.Account.Web.Areas.Account.Controllers.Models; | ||
|
||
public class QrCodeInfoResult | ||
{ | ||
public string Key { get; set; } | ||
public QrCodeStatus Status { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
.../account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/Models/QrCodeUserInfoResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace LINGYUN.Abp.Account.Web.Areas.Account.Controllers.Models; | ||
|
||
public class QrCodeUserInfoResult : QrCodeInfoResult | ||
{ | ||
public string UserId { get; set; } | ||
public string UserName { get; set; } | ||
public string Picture { get; set; } | ||
} |
104 changes: 104 additions & 0 deletions
104
...odules/account/LINGYUN.Abp.Account.Web/Areas/Account/Controllers/QrCodeLoginController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using Asp.Versioning; | ||
using LINGYUN.Abp.Account.Web.Areas.Account.Controllers.Models; | ||
using LINGYUN.Abp.Identity.QrCode; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Threading.Tasks; | ||
using Volo.Abp; | ||
using Volo.Abp.Account; | ||
using Volo.Abp.AspNetCore.Mvc; | ||
using Volo.Abp.Identity; | ||
using Volo.Abp.Security.Claims; | ||
using Volo.Abp.Users; | ||
|
||
namespace LINGYUN.Abp.Account.Web.Areas.Account.Controllers; | ||
|
||
[Controller] | ||
[ControllerName("QrCodeLogin")] | ||
[Area(AccountRemoteServiceConsts.ModuleName)] | ||
[Route($"api/{AccountRemoteServiceConsts.ModuleName}/qrcode")] | ||
[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)] | ||
public class QrCodeLoginController : AbpControllerBase | ||
{ | ||
private readonly IdentityUserManager _userManager; | ||
private readonly IQrCodeLoginProvider _qrCodeLoginProvider; | ||
|
||
public QrCodeLoginController( | ||
IdentityUserManager userManager, | ||
IQrCodeLoginProvider qrCodeLoginProvider) | ||
{ | ||
_userManager = userManager; | ||
_qrCodeLoginProvider = qrCodeLoginProvider; | ||
} | ||
|
||
[HttpPost] | ||
[Route("generate")] | ||
[AllowAnonymous] | ||
public async Task<GenerateQrCodeResult> GenerateAsync() | ||
{ | ||
var qrCodeInfo = await _qrCodeLoginProvider.GenerateAsync(); | ||
|
||
return new GenerateQrCodeResult | ||
{ | ||
Key = qrCodeInfo.Key, | ||
}; | ||
} | ||
|
||
[HttpGet] | ||
[Route("{key}/check")] | ||
[AllowAnonymous] | ||
public async Task<QrCodeUserInfoResult> CheckCodeAsync(string key) | ||
{ | ||
var qrCodeInfo = await _qrCodeLoginProvider.GetCodeAsync(key); | ||
|
||
return new QrCodeUserInfoResult | ||
{ | ||
Key = qrCodeInfo.Key, | ||
Status = qrCodeInfo.Status, | ||
Picture = qrCodeInfo.Picture, | ||
UserId = qrCodeInfo.UserId, | ||
UserName = qrCodeInfo.UserName, | ||
}; | ||
} | ||
|
||
[HttpPost] | ||
[Route("{key}/scan")] | ||
[Authorize] | ||
public async Task<QrCodeUserInfoResult> ScanCodeAsync(string key) | ||
{ | ||
var currentUser = await _userManager.GetByIdAsync(CurrentUser.GetId()); | ||
|
||
var picture = CurrentUser.FindClaim(AbpClaimTypes.Picture)?.Value; | ||
var userName = CurrentUser.FindClaim(AbpClaimTypes.Name)?.Value ?? currentUser.UserName; | ||
var userId = await _userManager.GetUserIdAsync(currentUser); | ||
|
||
var qrCodeInfo = await _qrCodeLoginProvider.ScanCodeAsync(key, | ||
new QrCodeScanParams(userId, userName, picture, currentUser.TenantId)); | ||
|
||
return new QrCodeUserInfoResult | ||
{ | ||
Key = qrCodeInfo.Key, | ||
Status = qrCodeInfo.Status, | ||
Picture = qrCodeInfo.Picture, | ||
UserId = qrCodeInfo.UserId, | ||
UserName = qrCodeInfo.UserName | ||
}; | ||
} | ||
|
||
[HttpPost] | ||
[Route("{key}/confirm")] | ||
[Authorize] | ||
public async Task<QrCodeUserInfoResult> ConfirmCodeAsync(string key) | ||
{ | ||
var qrCodeInfo = await _qrCodeLoginProvider.ConfirmCodeAsync(key); | ||
|
||
return new QrCodeUserInfoResult | ||
{ | ||
Key = qrCodeInfo.Key, | ||
Status = qrCodeInfo.Status, | ||
Picture = qrCodeInfo.Picture, | ||
UserId = qrCodeInfo.UserId, | ||
UserName = qrCodeInfo.UserName | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
aspnet-core/modules/identity/LINGYUN.Abp.Identity.AspNetCore.QrCode/FodyWeavers.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait /> | ||
</Weavers> |
30 changes: 30 additions & 0 deletions
30
aspnet-core/modules/identity/LINGYUN.Abp.Identity.AspNetCore.QrCode/FodyWeavers.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
24 changes: 24 additions & 0 deletions
24
...tity/LINGYUN.Abp.Identity.AspNetCore.QrCode/LINGYUN.Abp.Identity.AspNetCore.QrCode.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\..\..\configureawait.props" /> | ||
<Import Project="..\..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<AssemblyName>LINGYUN.Abp.Identity.AspNetCore.QrCode</AssemblyName> | ||
<PackageId>LINGYUN.Abp.Identity.AspNetCore.QrCode</PackageId> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<RootNamespace /> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Volo.Abp.Identity.AspNetCore" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LINGYUN.Abp.Identity.QrCode\LINGYUN.Abp.Identity.QrCode.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
20 changes: 20 additions & 0 deletions
20
...etCore.QrCode/LINGYUN/Abp/Identity/AspNetCore/QrCode/AbpIdentityAspNetCoreQrCodeModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using LINGYUN.Abp.Identity.QrCode; | ||
using Microsoft.AspNetCore.Identity; | ||
using Volo.Abp.Identity.AspNetCore; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace LINGYUN.Abp.Identity.AspNetCore.QrCode; | ||
|
||
[DependsOn( | ||
typeof(AbpIdentityQrCodeModule), | ||
typeof(AbpIdentityAspNetCoreModule))] | ||
public class AbpIdentityAspNetCoreQrCodeModule : AbpModule | ||
{ | ||
public override void PreConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
PreConfigure<IdentityBuilder>(builder => | ||
{ | ||
builder.AddTokenProvider<QrCodeUserTokenProvider>(QrCodeUserTokenProvider.ProviderName); | ||
}); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ntity.AspNetCore.QrCode/LINGYUN/Abp/Identity/AspNetCore/QrCode/QrCodeUserTokenProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.AspNetCore.DataProtection; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using IdentityUser = Volo.Abp.Identity.IdentityUser; | ||
|
||
namespace LINGYUN.Abp.Identity.QrCode; | ||
|
||
public class QrCodeUserTokenProvider : DataProtectorTokenProvider<IdentityUser> | ||
{ | ||
public static string ProviderName => QrCodeLoginProviderConsts.Name; | ||
public QrCodeUserTokenProvider( | ||
IDataProtectionProvider dataProtectionProvider, | ||
IOptions<DataProtectionTokenProviderOptions> options, | ||
ILogger<DataProtectorTokenProvider<IdentityUser>> logger) | ||
: base(dataProtectionProvider, options, logger) | ||
{ | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
aspnet-core/modules/identity/LINGYUN.Abp.Identity.QrCode/FodyWeavers.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
30 changes: 30 additions & 0 deletions
30
aspnet-core/modules/identity/LINGYUN.Abp.Identity.QrCode/FodyWeavers.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
25 changes: 25 additions & 0 deletions
25
aspnet-core/modules/identity/LINGYUN.Abp.Identity.QrCode/LINGYUN.Abp.Identity.QrCode.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\..\..\configureawait.props" /> | ||
<Import Project="..\..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net9.0</TargetFrameworks> | ||
<AssemblyName>LINGYUN.Abp.Identity.QrCode</AssemblyName> | ||
<PackageId>LINGYUN.Abp.Identity.QrCode</PackageId> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<RootNamespace /> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Remove="LINGYUN\Abp\Identity\QrCode\Localization\Resources\*.json" /> | ||
<EmbeddedResource Include="LINGYUN\Abp\Identity\QrCode\Localization\Resources\*.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Volo.Abp.Identity.Domain" /> | ||
</ItemGroup> | ||
|
||
</Project> |
26 changes: 26 additions & 0 deletions
26
...entity/LINGYUN.Abp.Identity.QrCode/LINGYUN/Abp/Identity/QrCode/AbpIdentityQrCodeModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Volo.Abp.Identity; | ||
using Volo.Abp.Identity.Localization; | ||
using Volo.Abp.Localization; | ||
using Volo.Abp.Modularity; | ||
using Volo.Abp.VirtualFileSystem; | ||
|
||
namespace LINGYUN.Abp.Identity.QrCode; | ||
|
||
[DependsOn(typeof(AbpIdentityDomainModule))] | ||
public class AbpIdentityQrCodeModule : AbpModule | ||
{ | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
Configure<AbpVirtualFileSystemOptions>(options => | ||
{ | ||
options.FileSets.AddEmbedded<AbpIdentityQrCodeModule>(); | ||
}); | ||
|
||
Configure<AbpLocalizationOptions>(options => | ||
{ | ||
options.Resources | ||
.Get<IdentityResource>() | ||
.AddVirtualJson("/LINGYUN/Abp/Identity/QrCode/Localization/Resources"); | ||
}); | ||
} | ||
} |
Oops, something went wrong.