Netnr.Login 5.3.0

dotnet add package Netnr.Login --version 5.3.0                
NuGet\Install-Package Netnr.Login -Version 5.3.0                
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="Netnr.Login" Version="5.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Netnr.Login --version 5.3.0                
#r "nuget: Netnr.Login, 5.3.0"                
#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 Netnr.Login as a Cake Addin
#addin nuget:?package=Netnr.Login&version=5.3.0

// Install Netnr.Login as a Cake Tool
#tool nuget:?package=Netnr.Login&version=5.3.0                

Netnr.Login

第三方 OAuth2 授权登录,QQ、微信开放平台(Weixin)、微信公众平台(WeixinMP)、微博(Weibo)、淘宝(Taobao)、支付宝(Alipay)、钉钉(DingTalk)、飞书(Feishu)、华为(Huawei)、小米(Xiaomi)、AtomGit、码云(Gitee)、GitHub、GitLab、微软(Microsoft )、StackOverflow、谷歌(Google)、ORCID

安装 (NuGet)

Install-Package Netnr.Login

支持第三方登录

<table> <tr><th>三方</th><th>参考文档</th><th>应用申请(已登录)</th></tr> <tr> <td><img src="https://gs.zme.ink/static/login/qq.svg" height="30" title="QQ"></td> <td><a target="_blank" href="https://wiki.connect.qq.com/准备工作_oauth2-0">参考文档</a></td> <td><a target="_blank" href="https://connect.qq.com/manage.html">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/weixin.svg" height="30" title="微信开放平台/Weixin"></td> <td><a target="_blank" href="https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html">参考文档</a></td> <td><a target="_blank" href="https://open.weixin.qq.com">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/weixinmp.svg" height="30" title="微信公众平台/WeixinMP"></td> <td><a target="_blank" href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html">参考文档</a></td> <td><a target="_blank" href="https://mp.weixin.qq.com">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/weibo.svg" height="30" title="微博/Weibo"></td> <td><a target="_blank" href="https://open.weibo.com/wiki/Connect/login">参考文档</a></td> <td><a target="_blank" href="https://open.weibo.com/apps">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/taobao.svg" height="30" title="淘宝"></td> <td><a target="_blank" href="https://open.taobao.com/doc.htm?docId=118&docType=1&spm=a219a.7395903.0.0.6a4239715JvKjW">参考文档</a></td> <td><a target="_blank" href="https://console.open.taobao.com/">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/alipay.svg" height="30" title="支付宝/Alipay"></td> <td><a target="_blank" href="https://opendocs.alipay.com/open/263/105809">参考文档</a></td> <td><a target="_blank" href="https://open.alipay.com/develop/manage">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/dingtalk.svg" height="30" title="钉钉/DingTalk"></td> <td><a target="_blank" href="https://open.dingtalk.com/document/tutorial/scan-qr-code-to-log-on-to-third-party-websites">参考文档</a></td> <td><a target="_blank" href="https://open-dev.dingtalk.com/#/loginMan">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/feishu.svg" height="30" title="钉钉/DingTalk"></td> <td><a target="_blank" href="https://open.feishu.cn/document/common-capabilities/sso/web-application-sso/web-app-overview">参考文档</a></td> <td><a target="_blank" href="https://open.feishu.cn/app">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/huawei.svg" height="30" title="华为/Huawei"></td> <td><a target="_blank" href="https://developer.huawei.com/consumer/cn/doc/HMSCore-Guides/web-dev-guide-0000001050050895">参考文档</a></td> <td><a target="_blank" href="https://developer.huawei.com/consumer/cn/console/service/AppService">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/xiaomi.svg" height="30" title="小米/Xiaomi"></td> <td><a target="_blank" href="https://dev.mi.com/console/doc/detail?pId=707">参考文档</a></td> <td><a target="_blank" href="https://dev.mi.com/passport/oauth2/applist">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/atomgit.svg" height="30" title="AtomGit"></td> <td><a target="_blank" href="https://docs.atomgit.com/oauth/">参考文档</a></td> <td><a target="_blank" href="https://atomgit.com">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/gitee.svg" height="30" title="码云/Gitee"></td> <td><a target="_blank" href="https://gitee.com/api/v5/oauth_doc">参考文档</a></td> <td><a target="_blank" href="https://gitee.com/oauth/applications">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/github.svg" height="30" title="GitHub"></td> <td><a target="_blank" href="https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps">参考文档</a></td> <td><a target="_blank" href="https://github.com/settings/developers">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/gitlab.svg" height="30" title="GitLab"></td> <td><a target="_blank" href="https://docs.gitlab.com/ee/api/oauth2.html">参考文档</a></td> <td><a target="_blank" href="https://gitlab.com/oauth/applications">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/microsoft.svg" height="30" title="微软/Microsoft"></td> <td><a target="_blank" href="https://docs.microsoft.com/zh-cn/azure/active-directory/develop/v2-oauth2-auth-code-flow">参考文档</a></td> <td><a target="_blank" href="https://portal.azure.com/#view/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/~/RegisteredApps">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/stackoverflow.svg" height="30" title="Stack Overflow"></td> <td><a target="_blank" href="https://api.stackexchange.com">参考文档</a></td> <td><a target="_blank" href="https://stackapps.com/apps/oauth/register">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/google.svg" height="30" title="谷歌/Google"></td> <td><a target="_blank" href="https://developers.google.com/identity/protocols/oauth2/web-server">参考文档</a></td> <td><a target="_blank" href="https://console.developers.google.com/apis/credentials">应用申请</a></td> </tr> <tr> <td><img src="https://gs.zme.ink/static/login/orcid.svg" height="30" title="ORCID"></td> <td><a target="_blank" href="https://github.com/ORCID/ORCID-Source/blob/main/orcid-web/ORCID_AUTH_WITH_OPENID_CONNECT.md">参考文档</a></td> <td><a target="_blank" href="https://orcid.org/developer-tools">应用申请</a></td> </tr>
</table>

变更

v5 版本全面重写,不兼容以前,调用方法更简单简洁
移除 Newtonsoft.Json 组件,改为 System.Text.Json
微软含新旧模式(注意新旧版本标识不相同)
钉钉含新旧模式(新:企业内部开发 H5微应用;旧:移动应用接入 扫码登录)

2024-10-17

新增 AtomGit、ORCID、GitLab
删除 字段 PublicUserResult.Gender
修改 字段 PublicUserResult.IntroBio

2024-10-18

新增 华为 小米
修复 微博获取唯一标识的错误,以前的版本微博都有问题 严重缺陷
调整 PublicUserResult 类属性字段为 OpenId(有值,应用唯一)、UnionId(可能有值,跨应用唯一)
新增 PublicUserResult 类方法 GetId() => UnionId ?? OpenId;

使用

v4 旧版本使用示例 Netnr.Demo/Controllers/LoginController.cs

极简调用,详情参考 Netnr.Demo/Controllers/AccountController.cs

// 初始化配置,推荐使用 LoginTo.InitConfig 方法读取配置

QQ.AppId = "";
QQ.AppKey = "";
QQ.Redirect_Uri = "https://localhost/account/authcallback/qq";
/// <summary>
/// 登录、绑定
/// </summary>
/// <param name="id">哪家</param>
/// <returns></returns>
[HttpGet]
public IActionResult Auth([FromRoute] LoginWhich? id)
{
    if (id.HasValue)
    {
        //根据 state 字段加前缀 login 或 bind 来区分
        DocModel authResult = LoginTo.EntryOfStep<object, object>(id.Value, LoginStep.Authorize, stateCall: (state) => $"login_{state}");
        if (!string.IsNullOrEmpty(authResult.Raw))
        {
            return Redirect(authResult.Raw);
        }
    }

    return BadRequest();
}
/// <summary>
/// 回调
/// </summary>
/// <param name="id">哪家</param>
/// <param name="authResult">接收授权码</param>
/// <returns></returns>
[HttpGet]
public IActionResult AuthCallback([FromRoute] LoginWhich id, AuthorizeResult authResult)
{
    //极简拿到最终用户信息,参考详情可得到步骤信息
    var publicUser = LoginTo.Entry(id, authResult);

    var result = publicUser.ToJson(true);
    Console.WriteLine(result);

    return Ok(result);
}

注意

默认构建的授权调整链接是基于 PC,而有些是区分移动端、扫码等,需要根据客户端来源构建对应的授权跳转链接。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.3.0 121 10/18/2024
4.0.1 821 5/18/2021
4.0.0 606 11/28/2020
3.6.0 551 10/7/2020
3.5.2 957 1/18/2020
3.5.1 615 12/26/2019
3.5.0 608 11/12/2019
3.4.1 519 11/11/2019
3.4.0 517 11/9/2019
3.3.0-rc1 434 10/16/2019
3.2.0-beta1 479 9/20/2019
3.1.0 971 3/26/2019
3.0.1 605 3/6/2019
2.0.0 864 10/18/2018
1.0.0 783 10/9/2018

新增 华为 小米,修复 微博