在 Asp Net Core 6 中使用 Github 进行身份验证

Che*_*hil 5 c# asp.net authentication oauth asp.net-core

我想将 GitHub 身份验证添加到我的 Asp Net Core 6 项目中,但我在 Internet 上找到的所有内容都适用于旧版本的 Asp Net。我怎样才能添加它?

我将该Microsoft.AspNetCore.Authentication.OAuth包添加到我的项目中并创建了一个 Github OAuth 应用程序。我还添加了客户端 ID 和客户端密码

dotnet user-secrets set Github:ClientId <clientid>
dotnet user-secrets set Github:ClientSecret <clientsecret>
Run Code Online (Sandbox Code Playgroud)

我在网上搜索了教程,但只有使用Asp Net版本6以下的教程。

Jas*_*Pan 2

请使用AspNet.AspNet.Security.OAuth.GitHubOctoKit图书馆。您需要在项目路径中运行安装命令。喜欢:

PM> cd .\GithubAuth
PM> Install-Package AspNet.Security.OAuth.GitHub -Version 6.0.5
PM> Install-Package Octokit -Version 0.50.0
Run Code Online (Sandbox Code Playgroud)

我在我的 dotnet core 6 应用程序中进行了测试,效果很好。

欲了解更多详情,请查看以下博客:

在这篇博客中,提到了Linux平台,你可以忽略它。

为 ASP.NET Core 应用程序添加 GitHub OpenID 身份验证