AsthaIT.SocialLogin
1.0.0
See the version list below for details.
dotnet add package AsthaIT.SocialLogin --version 1.0.0
NuGet\Install-Package AsthaIT.SocialLogin -Version 1.0.0
<PackageReference Include="AsthaIT.SocialLogin" Version="1.0.0" />
<PackageVersion Include="AsthaIT.SocialLogin" Version="1.0.0" />
<PackageReference Include="AsthaIT.SocialLogin" />
paket add AsthaIT.SocialLogin --version 1.0.0
#r "nuget: AsthaIT.SocialLogin, 1.0.0"
#addin nuget:?package=AsthaIT.SocialLogin&version=1.0.0
#tool nuget:?package=AsthaIT.SocialLogin&version=1.0.0
AIT.Packages.SocialLogin
AsthaIT SocialLogin is a simple and extensible library for integrating social login functionality (Google, Facebook, Github.) into .NET applications. It streamlines OAuth setup, handles authentication flows securely, and provides user information with minimal configuration.
Installation
dotnet add package AsthaIT.SocialLogin
Usage
To use the library, create an instance of the desired client (e.g., AITGoogleClient
, AITGithubClient
, or AITFacebookClient
) with your application's credentials, and call the appropriate methods to generate login URLs, exchange authorization codes for access tokens, and retrieve user profiles.
AITGoogleClient
The AITGoogleClient
class provides methods to interact with Google's OAuth 2.0 API for authentication and user data retrieval.
Constructor
- clientId: The client ID of your Google application.
- clientSecret: The client secret of your Google application.
- redirectUrl: The redirect URL configured in your Google application.
Methods
1. GetLoginUrl
Generates the Google login URL for user authentication.
- state: A unique string to maintain state between the request and callback.
- Returns: A URL string for Google login.
2. GetAccessTokenAsync
Exchanges the authorization code for an access token.
- code: The authorization code received from Google after user login.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the access token.
3. RefreshAccessTokenAsync
Refreshes the access token using a refresh token.
- refreshToken: The refresh token obtained during the initial token exchange.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the refreshed access token.
4. RevokeTokenAsync
Revokes a token (access or refresh) using Google's token revocation endpoint.
- token: The token to be revoked.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
indicating the result of the revocation.
5. GetUserProfileAsync
Fetches the authenticated user's profile information.
- accessToken: The access token obtained after user authentication.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the user's profile data.
API Endpoints Used
- Login URL:
https://accounts.google.com/o/oauth2/v2/auth
- Access Token URL:
https://oauth2.googleapis.com/token
- Token Revoke URL:
https://oauth2.googleapis.com/revoke
- Profile URL:
https://www.googleapis.com/oauth2/v2/userinfo
AITGithubClient
The AITGithubClient
class provides methods to interact with GitHub's OAuth 2.0 API for authentication and user data retrieval.
Constructor
- clientId: The client ID of your GitHub application.
- clientSecret: The client secret of your GitHub application.
- redirectUrl: The redirect URL configured in your GitHub application.
Methods
1. GetLoginUrl
Generates the GitHub login URL for user authentication.
- state: A unique string to maintain state between the request and callback.
- Returns: A URL string for GitHub login.
2. GetUserProfileAsync
Fetches the authenticated user's profile information.
- accessToken: The access token obtained after user authentication.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the user's profile data.
3. GetUserEmailsAsync
Fetches the authenticated user's profile information.
- accessToken: The access token obtained after user authentication.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the user's profile data.
3. GetUserEmailsAsync
Fetches the authenticated user's email addresses.
- accessToken: The access token obtained after user authentication.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing a list of the user's email addresses.
4. GetAccessTokenAsync
Exchanges the authorization code for an access token.
- code: The authorization code received from GitHub after user login.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the access token.
5. RevokeAccessTokenAsync
Revokes the specified access token.
- accessToken: The access token to be revoked.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
indicating the result of the revocation.
API Endpoints Used
- Access Token URL:
https://github.com/login/oauth/access_token
- Revoke Access Token URL:
https://api.github.com/applications/{client_id}/token
- Login URL:
https://github.com/login/oauth/authorize
- Profile URL:
https://api.github.com/user
- Profile Emails URL:
https://api.github.com/user/emails
AITFacebookClient
The AITFacebookClient
class provides methods to interact with Facebook's OAuth 2.0 API for authentication and user data retrieval.
Constructor
- clientId: The client ID of your Facebook application.
- clientSecret: The client secret of your Facebook application.
- redirectUrl: The redirect URL configured in your Facebook application.
Methods
1. GetLoginUrl
Generates the Facebook login URL for user authentication.
- state: A unique string to maintain state between the request and callback.
- Returns: A URL string for Facebook login.
2. GetAccessTokenAsync
Exchanges the authorization code for an access token.
- code: The authorization code received from Facebook after user login.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the access token.
3. GetUserProfileAsync
Fetches the authenticated user's profile information.
- accessToken: The access token obtained after user authentication.
- cancellationToken: Optional cancellation token.
- Returns: An
APIResponse
containing the user's profile data.
API Endpoints Used
- Login URL:
https://www.facebook.com/v19.0/dialog/oauth
- Access Token URL:
https://graph.facebook.com/v19.0/oauth/access_token
- Profile URL:
https://graph.facebook.com/me
License
MIT License
Author
Developed and maintained by AIT.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- AsthaIT.RestClient (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.