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" />
                    
Directory.Packages.props
<PackageReference Include="Andrew.CommonUse.OAuth" />
                    
Project file
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
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=Andrew.CommonUse.OAuth&version=1.0.5
                    
Install as a Cake Tool
# 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


โญ 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
   [![NuGet](https://img.shields.io/nuget/v/Andrew.CommonUse.OAuth.svg)](https://www.nuget.org/packages/Andrew.CommonUse.OAuth)
   [![License](https://img.shields.io/github/license/sharisp/OAuth2Service.svg)](LICENSE)
  1. Roadmap or To-Do section

    ## ๐Ÿ›ฃ๏ธ Roadmap
    - [x] Google OAuth support  
    - [ ] GitHub OAuth support  
    - [ ] Microsoft OAuth support  
    - [ ] Facebook OAuth support  
    
Product 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.

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.5 219 11/15/2025
1.0.4 219 11/15/2025
1.0.3 234 11/3/2025
1.0.2 220 11/3/2025
1.0.1 198 11/2/2025
1.0.0 211 11/2/2025