V.User.OAuth
1.0.3
See the version list below for details.
dotnet add package V.User.OAuth --version 1.0.3
NuGet\Install-Package V.User.OAuth -Version 1.0.3
<PackageReference Include="V.User.OAuth" Version="1.0.3" />
paket add V.User.OAuth --version 1.0.3
#r "nuget: V.User.OAuth, 1.0.3"
// Install V.User.OAuth as a Cake Addin #addin nuget:?package=V.User.OAuth&version=1.0.3 // Install V.User.OAuth as a Cake Tool #tool nuget:?package=V.User.OAuth&version=1.0.3
V.User.OAuth
木叉一人工作室封装的 OAuth 类库,支持授权登录成功后进行自定义操作
适用于 asp.net core 的 OAuth 实现,框架支持在授权后自定义操作,比如用户入库、生成JWT便于后续鉴权等
Nuget
官方示例项目
支持的第三方平台
Github
"OAuth": {
"Github": {
"client_id": "xxx",
"client_secret": "xxx"
}
}
Github 应用设置页面回调地址格式:https://localhost:7167/usermodule
Gitee
"OAuth": {
"Gitee": {
"client_id": "xxx",
"client_secret": "xxx"
}
}
Gitee 应用回调地址格式:https://localhost:7167/usermodule/authorize?service=gitee
Baidu
"OAuth": {
"Baidu": {
"client_id": "xxx",
"client_secret": "xxx"
}
}
Baidu 应用回调地址格式:https://localhost:7167/usermodule/authorize?service=baidu
百度估计很久没维护 OAuth 功能了,应用申请页面比较拉跨,授权得到的用户信息也很少
在 asp.net core 项目中使用
创建自定义类型实现
ILoginService
接口public class LoginService : ILoginService { public async Task Login(HttpContext context, UserInfo user) { if (user.Source == "github") { // do something } if (user.Source == "gitee") { // do something } await context.Response.WriteAsJsonAsync(user); } }
往容器内注入服务
services.AddTransient<ILoginService, LoginService>()
启用 OAuth
public void ConfigureServices(IServiceCollection services) { services.AddOAuth(); } public void Configure(IApplicationBuilder app) { app.UseOAuth(); }
OAuth 授权登录链接: https://localhost:7167/usermodule/oauth?service=github
注意: 如果你使用的是 Github 授权登录,你可以在
https://localhost:7167/usermodule/oauth?service=github
之后添加任何参数, 例如https://localhost:7167/usermodule/oauth?service=github&key1=value1&key2=value2
, 你将能够在 ILoginService 的回调方法中通过 context 获取到这些参数但是如果用的是 Gitee,在 url 添加的参数将无法在 Login 方法中获取到,因为 Gitee 的回调链接必须是固定配置的,不接受动态参数。因此,若在使用 Gitee 授权结束后,希望能有不同的处理流程,需要在后续流程进行处理,比如需要区分平台,打开不同的页面,则可以在 Login 方法中返回一个中间页面,处理跳转逻辑。
其他三方平台还在努力支持中...
接口基地址配置
当接口挂在代理服务器下,部分场景会导致 asp.net core 获取不到完整的原始请求链接,因此增加了 OAuth:BaseUrl 配置用于配置接口基地址(即 /usermodule 前面的部分),若该配置为空,则认为可获取到完整原始请求链接,会自动拼接出回调地址
"OAuth": {
"Baidu": {
"client_id": "xxx",
"client_secret": "xxx"
},
"BaseUrl": "http://localhost/test"
}
如果这个项目有帮助到你,不妨支持一下
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.0)
- Microsoft.Extensions.Http (>= 3.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.0)
- V.Common.Extensions (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on V.User.OAuth:
Package | Downloads |
---|---|
V.User
木叉一人工作室封装的用户模块,包括手机号、邮箱登录以及 OAuth 授权登录等 |
GitHub repositories
This package is not used by any popular GitHub repositories.