Andrew.CommonUse.OAuth
1.0.5
dotnet add package Andrew.CommonUse.OAuth --version 1.0.5
NuGet\Install-Package Andrew.CommonUse.OAuth -Version 1.0.5
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="Andrew.CommonUse.OAuth" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Andrew.CommonUse.OAuth" Version="1.0.5" />
<PackageReference Include="Andrew.CommonUse.OAuth" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Andrew.CommonUse.OAuth --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Andrew.CommonUse.OAuth, 1.0.5"
#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.
#:package Andrew.CommonUse.OAuth@1.0.5
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Andrew.CommonUse.OAuth&version=1.0.5
#tool nuget:?package=Andrew.CommonUse.OAuth&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
# Andrew.CommonUse.OAuth
A lightweight and extensible **OAuth 2.0 integration framework** for .NET applications.
Provides a unified interface to handle multiple OAuth providers such as **Google**, **GitHub**, **Microsoft**, and more.
(Currently supports **Google**, with more providers coming soon.)
---
## ๐ Features
- โ
Simple and clean API for **Google OAuth 2.0**
- ๐งฉ Unified OAuth interface across multiple providers
- โ๏ธ Configuration-driven via `appsettings.json`
- ๐ง Fully supports **Dependency Injection** and `IOptions<T>`
- ๐ Built-in state validation and secure token exchange
- ๐งช Designed for easy unit testing and mocking
- ๐ง Easily extendable for future providers (GitHub, Microsoft, Facebook, etc.)
---
## ๐ฆ Installation
Install via NuGet:
```bash
dotnet add package Andrew.CommonUse.OAuth
โ๏ธ Configuration
Add your OAuth settings to appsettings.json:
{
"OAuth": {
"Google": {
"AuthUrl": "https://accounts.google.com/o/oauth2/v2/auth",
"TokenUrl": "https://oauth2.googleapis.com/token",
"ClientId": "YOUR_CLIENT_ID",
"ClientSecret": "YOUR_CLIENT_SECRET",
"RedirectUrl": "https://localhost:5001/api/auth/callback",
"Scope": "profile email"
}
}
}
๐งฉ Usage Example
1๏ธโฃ Register OAuth service in DI
builder.Services.AddOAuthService(builder.Configuration);
2๏ธโฃ Inject and use the service
public class OAuthController(
[FromKeyedServices(OAuthProviderEnum.Google)] IOAuthService googleOAuthService
) : ControllerBase
{
//get GetAuthorizationUrl
var state = Guid.NewGuid().ToString();
var authUrl = googleOAuthService.GetAuthorizationUrl(state);
// get callback userinfo
// GET: api/auth/callback
[HttpGet("callback")]
public async Task<IActionResult> Callback(string state, string code, string error = "")
{
var response = await googleOAuthService.OAuthCallBack(state, code, error);
if (!response.Success)
return BadRequest(response.ErrorMsg);
return Ok(response.UserInfo);
}
}
3๏ธโฃ Example output
Visit this URL to authorize: https://accounts.google.com/o/oauth2/v2/auth?...
User Info: {"Id":"12345","Email":"user@gmail.com","Name":"John Doe"}
๐งฐ Extend to Other Providers
Implement your own provider by inheriting from IOAuthService and configuring new endpoints in appsettings.json.
Each provider can define its own:
- Authorization URL
- Token URL
- User Info URL
- Client credentials and scopes
๐ Links
- NuGet: Andrew.CommonUse.OAuth
- GitHub: https://github.com/sharisp/OAuth2Service
โญ If you find this project helpful, please give it a star on GitHub!
---
## ๐ก Optional Additions
You could add:
1. **Badges** (NuGet, build status, license, etc.)
```markdown
[](https://www.nuget.org/packages/Andrew.CommonUse.OAuth)
[](LICENSE)
Roadmap or To-Do section
## ๐ฃ๏ธ Roadmap - [x] Google OAuth support - [ ] GitHub OAuth support - [ ] Microsoft OAuth support - [ ] Facebook OAuth support
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.