Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Firebase.Auth;
- using Firebase.Extensions;
- using Google;
- using System;
- using System.Threading.Tasks;
- public static class GoogleManager
- {
- private static readonly string GOOGLE_WEB_API = "751656854746-i7g3sim0abgm7130hl83d2rkpq673vk5.apps.googleusercontent.com";
- private static GoogleSignInConfiguration configuration;
- private static bool isInit;
- public static void Init(Action _callBack)
- {
- if (isInit)
- {
- _callBack?.Invoke();
- return;
- }
- configuration = new GoogleSignInConfiguration
- {
- WebClientId = GOOGLE_WEB_API,
- RequestIdToken = true
- };
- isInit = true;
- _callBack?.Invoke();
- }
- public static void Login(Action<Credential> _loginSuccess, Action<string> _loginFailed)
- {
- GoogleSignIn.Configuration = configuration;
- GoogleSignIn.Configuration.UseGameSignIn = false;
- GoogleSignIn.Configuration.RequestIdToken = true;
- GoogleSignIn.Configuration.RequestEmail = true;
- GoogleSignIn.DefaultInstance.SignIn()
- .ContinueWithOnMainThread((_task) => OnGoogleAuthenticationFinished(_task, _loginSuccess, _loginFailed));
- }
- private static void OnGoogleAuthenticationFinished(Task<GoogleSignInUser> _task, Action<Credential> _loginSuccess, Action<string> _loginFailed)
- {
- if (_task.IsFaulted)
- {
- _loginFailed?.Invoke("There was a fault, if this keeps happening please contact support:");
- }
- else if (_task.IsCanceled)
- {
- _loginFailed?.Invoke("Looks like you have canceled signin with google");
- }
- else
- {
- string _token = _task.Result.IdToken;
- var _credential = GoogleAuthProvider.GetCredential(_token, null);
- _loginSuccess?.Invoke(_credential);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement