Bee.OAuth2.AspNet
1.0.2
dotnet add package Bee.OAuth2.AspNet --version 1.0.2
NuGet\Install-Package Bee.OAuth2.AspNet -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="Bee.OAuth2.AspNet" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bee.OAuth2.AspNet --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bee.OAuth2.AspNet, 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 Bee.OAuth2.AspNet as a Cake Addin #addin nuget:?package=Bee.OAuth2.AspNet&version=1.0.2 // Install Bee.OAuth2.AspNet as a Cake Tool #tool nuget:?package=Bee.OAuth2.AspNet&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bee.OAuth2.AspNet
Bee.OAuth2.AspNet is an OAuth2 authentication library designed for ASP.NET WebForms / MVC, supporting Google, Facebook, LINE, and Azure.
📦 Installation
Install via NuGet Package Manager:
dotnet add package Bee.OAuth2.AspNet
🌍 Supported OAuth2 Providers
- ✅ LINE
- ✅ Azure (Microsoft Entra ID)
🚀 Usage Example (ASP.NET WebForms)
Register Google OAuth2 in Global.asax
using Bee.OAuth2;
using Bee.OAuth2.Providers;
protected void Application_Start()
{
var options = new TGoogleOAuthOptions()
{
ClientId = "xxxx",
ClientSecret = "xxxx",
RedirectUri = "xxxx",
UsePKCE = true
};
var client = new TOAuthClient(options);
OAuthManager.RegisterClient("Google", client);
}
Redirect to OAuth Authorization Page in Login Page
OAuthManager.RedirectToAuthorization("Google");
Validate OAuth2 Callback and Retrieve User Information
var result = await OAuthManager.ValidateAuthorization();
Response.Write(
$"ProviderName : {result.ProviderName}<br/>" +
$"UserID : {result.UserInfo.UserId}<br/>" +
$"UserName : {result.UserInfo.UserName}<br/>" +
$"Email : {result.UserInfo.Email}<br/>" +
$"RawJson : {result.UserInfo.RawJson}");
🚀 Usage Example (ASP.NET MVC)
Register Google OAuth2 in Startup.cs
using Bee.OAuth2;
using Bee.OAuth2.Providers;
public void Configuration(IAppBuilder app)
{
var options = new TGoogleOAuthOptions()
{
ClientId = "xxxx",
ClientSecret = "xxxx",
RedirectUri = "xxxx",
UsePKCE = true
};
var client = new TOAuthClient(options);
OAuthManager.RegisterClient("Google", client);
}
Redirect to OAuth Authorization Page in Controller
public ActionResult Login()
{
return Redirect(OAuthManager.GetAuthorizationUrl("Google"));
}
Validate OAuth2 Callback and Retrieve User Information in Controller
public async Task<ActionResult> Callback()
{
var result = await OAuthManager.ValidateAuthorization();
return Content($"ProviderName: {result.ProviderName}\n" +
$"UserID: {result.UserInfo.UserId}\n" +
$"UserName: {result.UserInfo.UserName}\n" +
$"Email: {result.UserInfo.Email}\n" +
$"RawJson: {result.UserInfo.RawJson}");
}
📜 License
This project is licensed under the MIT License.
Bee.OAuth2.AspNet(中文)
Bee.OAuth2.AspNet 是一個專為 ASP.NET WebForms / MVC 設計的 OAuth2 認證函式庫,支援 Google、Facebook、LINE、Azure 等 OAuth2 提供者。
📦 安裝方式
透過 NuGet 安裝:
dotnet add package Bee.OAuth2.AspNet
🌍 支援的 OAuth2 提供者
- ✅ LINE
- ✅ Azure(Microsoft Entra ID)
🚀 使用範例(ASP.NET WebForms)
在 Global.asax 註冊 Google OAuth2
using Bee.OAuth2;
using Bee.OAuth2.Providers;
protected void Application_Start()
{
var options = new TGoogleOAuthOptions()
{
ClientId = "xxxx",
ClientSecret = "xxxx",
RedirectUri = "xxxx",
UsePKCE = true
};
var client = new TOAuthClient(options);
OAuthManager.RegisterClient("Google", client);
}
在 login 頁面轉向 OAuth 授權頁面
OAuthManager.RedirectToAuthorization("Google");
在 callback 頁面驗證 OAuth2 回傳授權碼,並取得用戶資料
var result = await OAuthManager.ValidateAuthorization();
Response.Write(
$"ProviderName : {result.ProviderName}<br/>" +
$"UserID : {result.UserInfo.UserId}<br/>" +
$"UserName : {result.UserInfo.UserName}<br/>" +
$"Email : {result.UserInfo.Email}<br/>" +
$"RawJson : {result.UserInfo.RawJson}");
🚀 使用範例(ASP.NET MVC)
在 Startup.cs 註冊 Google OAuth2
using Bee.OAuth2;
using Bee.OAuth2.Providers;
public void Configuration(IAppBuilder app)
{
var options = new TGoogleOAuthOptions()
{
ClientId = "xxxx",
ClientSecret = "xxxx",
RedirectUri = "xxxx",
UsePKCE = true
};
var client = new TOAuthClient(options);
OAuthManager.RegisterClient("Google", client);
}
在 Controller 中轉向 OAuth 授權頁面
public ActionResult Login()
{
return Redirect(OAuthManager.GetAuthorizationUrl("Google"));
}
在 Controller 中驗證 OAuth2 回傳授權碼,並取得用戶資料
public async Task<ActionResult> Callback()
{
var result = await OAuthManager.ValidateAuthorization();
return Content($"ProviderName: {result.ProviderName}\n" +
$"UserID: {result.UserInfo.UserId}\n" +
$"UserName: {result.UserInfo.UserName}\n" +
$"Email: {result.UserInfo.Email}\n" +
$"RawJson: {result.UserInfo.RawJson}");
}
📜 授權
本專案採用 MIT License。
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.8
- Bee.Base (>= 3.0.1)
- Bee.OAuth2 (>= 1.0.2)
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 |
---|---|---|
1.0.2 | 34 | 2/14/2025 |