SocialAuthentication .NET library verifies the social login access token in the backend & return necessary infomations to identify the user.
$ dotnet add package Rapplis.SocialAuthenticationSocialAuthentication .NET library verifies the social login access token in the backend & return necessary infomations to identify the user.
The access token has to be fetched in frontend applicaton by signing in thorugh social authentication provider.
Currently this library supports 3 providers- google,apple & facebook
Install Rapplis.SocialAuhentication from NuGet Package Manager.
Install-Package Rapplis.SocialAuhentication
There is some setup to be done in the frontend part to make this library work smoothly. If you care about only backend, just ignore this section.
https://www.googleapis.com/auth/userinfo.profilehttps://www.googleapis.com/auth/userinfo.emailhttps://www.googleapis.com/auth/user.gender.readhttps://www.googleapis.com/auth/user.birthday.reademail, public_profile, user_birthday, user_gender.ClientId for apple sign in.email, fullName. await SocialAuth.GetUser(data);
| Parameter Type | Return Type |
|---|---|
SocialAuthData | SocialUser |
| Variable | Type | Value |
|---|---|---|
string | google | |
string | facebook | |
| Apple | string | apple |
This model is accepted as peremeter in GetUser method.
| Field | Type | Description |
|---|---|---|
| Provider | string | required* provider name mentioned in SocialAuthProvider |
| Token | string | required* access token fetched through signing in social provider |
| AppleClientId | string | required for apple* client id from apple developer console |
This model is returned by GetUser method.
| Field | Type | Description |
|---|---|---|
| Id | string | Unique ID fetched from login provider which has to be used for identifying users |
string? | nullable Email address of the user | |
| EmailVerified | bool | If email address have verified by social auth provider |
| Name | String? | nullable User's full name |
| FirstName | String? | nullable First Name of the user |
| LastName | String? | nullable Last Name of the user |
| Picture | String? | nullable Image url of user's profile picture |
| Locale | String? | nullable User's locale |
| Gender | String? | nullable Gender of the user |
| Birthday | DateTime? | nullable User's birthday |
| Provider | String | provider name mentioned in SocialAuthProvider |
First you have to get the access token of a provider from user through api or however you are implementing. Pass the provider name to validate the access token and get a user with unique id provided by the social authentication provider. Here is an example of Google Authentication.
var googleAuthData = new SocialAuthData {
Token = "access_token_got_from_user",
Provider = SocialAuthProvider.Google,
};
SocialUser? socialUser = null;
try
{
socialUser = await SocialAuth.GetUser(googleAuthData);
}
catch (Exception e)
{
//todo handle error
}
The objective of this library is to verify social authentication token and get user data froms social authentication providers in the backend.
Just as beginning, it supports only 3 providers- google, apple & facebook. Hope to implement more providers soon. Even though it is properly tested, it may have some edge case issues. Feel free to submit issue on Github Repository. You're also welcome to contribute to this package.
Follow me for more on github/rafid08