BurakKontas.OAuth2.Google 1.0.1

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

// Install BurakKontas.OAuth2.Google as a Cake Tool
#tool nuget:?package=BurakKontas.OAuth2.Google&version=1.0.1                

OAuth 2.0 Client

This project provides a C# client for interacting with OAuth 2.0 services. Below you'll find information on how to use and configure.

Features

  • Google OAuth 2.0 login and access token retrieval
  • Token renewal support
  • OAuth 2.0 login URL generation

Requirements

  • .NET 6.0 or newer
  • FluentValidation
  • Xunit
  • Moq
  • FluentAssertions

Installation

NuGet Packages

The project includes the necessary NuGet packages. Ensure the following packages are installed:

  • FluentValidation
  • Xunit
  • Moq
  • FluentAssertions

Configuration

To use the Google OAuth 2.0 client, you need to create a GoogleOAuthData object containing the required configuration details. Here is an example configuration:

var googleOAuthData = new GoogleOAuthData
{
    GoogleUrl = new Uri("https://accounts.google.com/o/oauth2/v2/auth?"),
    GoogleTokenUrl = new Uri("https://oauth2.googleapis.com/token"),
    ClientId = "test-client-id",
    ClientSecret = "test-client-secret",
    RedirectUri = new Uri("https://example.com/callback"),
    AccessType = GoogleAccessType.Online,
    Prompt = GooglePrompt.Consent,
    Scope = new List<GoogleScopes> { GoogleScopes.OpenId, GoogleScopes.Email },
    ResponseType = GoogleResponseType.Code,
    State = Guid.NewGuid().ToString(),
    GrantType = GoogleGrantType.AuthorizationCode
};

Usage

Creating the Client

You can create an instance of GoogleClient using the GoogleOAuthData object and an HttpClient:

var httpClient = new HttpClient();
var googleClient = new GoogleClient(googleOAuthData, httpClient);

Logging In

To log in using an authorization code, use the LoginAsync method of any client:

const string code = "test-auth-code";
var loginResponse = await googleClient.LoginAsync(code);
Console.WriteLine($"Access Token: {loginResponse?.AccessToken}");

Token Renewal

To get a new access token using a refresh token, use the RefreshTokenAsync method of any client:

const string refreshToken = "test-refresh-token";
var response = await googleClient.RefreshTokenAsync(refreshToken);

Console.WriteLine($"Access Token: {response?.AccessToken}");

Generating Login URL

To generate the URL needed to start the OAuth 2.0 login process, use the GetLoginUrl method of any client:

var url = await googleClient.GetLoginUrl();

Console.WriteLine($"Login URL: {url}");

Contributors

BurakKontas - Project Owner and Lead Developer

License

This project is licensed under the MIT License.

TODO

  • Implemented
    • Google OAuth2 Implementation
  • Roadmap
    • Meta OAuth2 Implementation
    • Apple OAuth2 Implementation
    • X OAuth2 Implementation
    • Github OAuth2 Implementation
    • Discord OAuth2 Implementation
    • Linkedin OAuth2 Implementation
    • Steam OAuth2 Implementation
    • Twitch OAuth2 Implementation
    • Epic Games OAuth2 Implementation
    • Sony Playstation OAuth2 Implementation
    • Xbox OAuth2 Implementation

Version Notes

  • 1.0.0
    • Initial release
  • 1.0.1
    • Added from string methods for enums
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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BurakKontas.OAuth2.Google:

Package Downloads
BurakKontas.OAuth2.Google.Polly

Resilience pattern with polly for BurakKontas.OAuth2.Google package.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 124 9/1/2024
1.0.0 127 9/1/2024