V.User.OAuth 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package V.User.OAuth --version 1.0.2                
NuGet\Install-Package V.User.OAuth -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="V.User.OAuth" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add V.User.OAuth --version 1.0.2                
#r "nuget: V.User.OAuth, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install V.User.OAuth as a Cake Addin
#addin nuget:?package=V.User.OAuth&version=1.0.2

// Install V.User.OAuth as a Cake Tool
#tool nuget:?package=V.User.OAuth&version=1.0.2                

V.User.OAuth

木叉一人工作室封装的 OAuth 类库,支持授权登录成功后进行自定义操作

适用于 asp.net core 的 OAuth 实现,框架支持在授权后自定义操作,比如用户入库、生成JWT便于后续鉴权等

Nuget

V.User.OAuth

官方示例项目

V.TouristGuide

支持的第三方平台

Github

"OAuth": {
    "Github": {
        "client_id": "xxx",
        "client_secret": "xxx"
    }
}

Github OAuth 应用申请链接

Github 应用设置页面回调地址格式:https://localhost:7167/usermodule

Gitee

"OAuth": {
    "Gitee": {
        "client_id": "xxx",
        "client_secret": "xxx"
    }
}

Gitee OAuth 应用申请链接

Gitee 应用回调地址格式:https://localhost:7167/usermodule/authorize?service=gitee

Baidu

"OAuth": {
    "Baidu": {
        "client_id": "xxx",
        "client_secret": "xxx"
    }
}

Baidu OAuth 应用申请链接

Baidu 应用回调地址格式:https://localhost:7167/usermodule/authorize?service=baidu

百度估计很久没维护 OAuth 功能了,应用申请页面比较拉跨,授权得到的用户信息也很少

在 asp.net core 项目中使用

  1. 创建自定义类型实现 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);
        }
    }
    
  2. 往容器内注入服务 services.AddTransient<ILoginService, LoginService>()

  3. 启用 OAuth

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddOAuth();
    }
    
    public void Configure(IApplicationBuilder app)
    {
        app.UseOAuth();
    }
    
  4. 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 方法中返回一个中间页面,处理跳转逻辑。

其他三方平台还在努力支持中...

如果这个项目有帮助到你,不妨支持一下

alternate text is missing from this package README image alternate text is missing from this package README image

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.1.0 138 7/12/2024
1.0.3 832 10/5/2022
1.0.2 640 10/5/2022
1.0.1 391 10/5/2022
1.0.0 657 10/4/2022