feat: 增加微信登陆认证模块

This commit is contained in:
Argo Zhang 2019-09-18 19:58:04 +08:00
parent 14567e29ab
commit b1135d96f1
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
5 changed files with 27 additions and 4 deletions

View File

@ -3,6 +3,7 @@ using Bootstrap.DataAccess;
using Longbow.GiteeAuth; using Longbow.GiteeAuth;
using Longbow.GitHubAuth; using Longbow.GitHubAuth;
using Longbow.Web; using Longbow.Web;
using Longbow.WeChatAuth;
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
@ -199,5 +200,16 @@ namespace Bootstrap.Admin.Controllers
var enabled = config.GetValue($"{nameof(GitHubOptions)}:Enabled", false); var enabled = config.GetValue($"{nameof(GitHubOptions)}:Enabled", false);
return Challenge(enabled ? GitHubDefaults.AuthenticationScheme : CookieAuthenticationDefaults.AuthenticationScheme); return Challenge(enabled ? GitHubDefaults.AuthenticationScheme : CookieAuthenticationDefaults.AuthenticationScheme);
} }
/// <summary>
/// WeChat 认证
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult WeChat([FromServices]IConfiguration config)
{
var enabled = config.GetValue($"{nameof(GitHubOptions)}:Enabled", false);
return Challenge(enabled ? WeChatDefaults.AuthenticationScheme : CookieAuthenticationDefaults.AuthenticationScheme);
}
} }
} }

View File

@ -60,7 +60,7 @@ namespace Bootstrap.Admin
services.AddSignalR().AddJsonProtocalDefault(); services.AddSignalR().AddJsonProtocalDefault();
services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false)); services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false));
services.AddResponseCompression(); services.AddResponseCompression();
services.AddBootstrapAdminAuthentication().AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure); services.AddBootstrapAdminAuthentication().AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure).AddWeChat(OAuthHelper.Configure);
services.AddSwagger(); services.AddSwagger();
services.AddButtonAuthorization(MenuHelper.AuthorizateButtons); services.AddButtonAuthorization(MenuHelper.AuthorizateButtons);
services.AddBootstrapAdminBackgroundTask(); services.AddBootstrapAdminBackgroundTask();

View File

@ -122,8 +122,8 @@
</a> </a>
</div> </div>
<div class="item"> <div class="item">
<a href="#" data-toggle="tooltip" title="微信-暂未实现"> <a href="~/Account/WeChat" data-toggle="tooltip" title="使用微信帐号登录">
<img class="item" src="~/images/weixin-2.svg" /> <img class="item" src="~/images/weixin.svg" />
</a> </a>
</div> </div>
<div class="item"> <div class="item">

View File

@ -82,6 +82,16 @@
"App": "0", "App": "0",
"StarredUrl": "https://api.github.com/user/starred/ArgoZhang/BootstrapAdmin" "StarredUrl": "https://api.github.com/user/starred/ArgoZhang/BootstrapAdmin"
}, },
"WeChatOptions": {
"Enabled": true,
"ClientId": "wxe2944ebb9e66551c",
"ClientSecret": "a4e36ddb18af218818e44bb7b8744fe6",
"CallbackPath": "/signin-weixin",
"HomePath": "/Admin/Profiles",
"Scope": [ "snsapi_login" ],
"Roles": [ "Administrators" ],
"App": "0"
},
"SMSOptions": { "SMSOptions": {
"CompanyCode": "<CompanyCode>", "CompanyCode": "<CompanyCode>",
"MD5Key": "MD5Key", "MD5Key": "MD5Key",

View File

@ -7,13 +7,14 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" /> <PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" /> <PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Data" Version="2.3.7" /> <PackageReference Include="Longbow.Data" Version="2.3.8" />
<PackageReference Include="Longbow.GiteeAuth" Version="2.2.0" /> <PackageReference Include="Longbow.GiteeAuth" Version="2.2.0" />
<PackageReference Include="Longbow.GitHubAuth" Version="2.2.0" /> <PackageReference Include="Longbow.GitHubAuth" Version="2.2.0" />
<PackageReference Include="Longbow.Logging" Version="2.2.13" /> <PackageReference Include="Longbow.Logging" Version="2.2.13" />
<PackageReference Include="Longbow.PetaPoco" Version="1.0.2" /> <PackageReference Include="Longbow.PetaPoco" Version="1.0.2" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" /> <PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Web" Version="2.2.16" /> <PackageReference Include="Longbow.Web" Version="2.2.16" />
<PackageReference Include="Longbow.WeChatAuth" Version="2.2.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
<PackageReference Include="PetaPoco.Extensions" Version="1.0.9" /> <PackageReference Include="PetaPoco.Extensions" Version="1.0.9" />
</ItemGroup> </ItemGroup>