Advertisement
Learning000001

Untitled

Oct 2nd, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using Firebase.Auth;
  2. using Firebase.Extensions;
  3. using Google;
  4. using System;
  5. using System.Threading.Tasks;
  6.  
  7. public static class GoogleManager
  8. {
  9. private static readonly string GOOGLE_WEB_API = "751656854746-i7g3sim0abgm7130hl83d2rkpq673vk5.apps.googleusercontent.com";
  10. private static GoogleSignInConfiguration configuration;
  11. private static bool isInit;
  12.  
  13. public static void Init(Action _callBack)
  14. {
  15. if (isInit)
  16. {
  17. _callBack?.Invoke();
  18. return;
  19. }
  20.  
  21. configuration = new GoogleSignInConfiguration
  22. {
  23. WebClientId = GOOGLE_WEB_API,
  24. RequestIdToken = true
  25. };
  26. isInit = true;
  27. _callBack?.Invoke();
  28. }
  29.  
  30. public static void Login(Action<Credential> _loginSuccess, Action<string> _loginFailed)
  31. {
  32. GoogleSignIn.Configuration = configuration;
  33. GoogleSignIn.Configuration.UseGameSignIn = false;
  34. GoogleSignIn.Configuration.RequestIdToken = true;
  35. GoogleSignIn.Configuration.RequestEmail = true;
  36.  
  37. GoogleSignIn.DefaultInstance.SignIn()
  38. .ContinueWithOnMainThread((_task) => OnGoogleAuthenticationFinished(_task, _loginSuccess, _loginFailed));
  39. }
  40.  
  41. private static void OnGoogleAuthenticationFinished(Task<GoogleSignInUser> _task, Action<Credential> _loginSuccess, Action<string> _loginFailed)
  42. {
  43. if (_task.IsFaulted)
  44. {
  45. _loginFailed?.Invoke("There was a fault, if this keeps happening please contact support:");
  46. }
  47. else if (_task.IsCanceled)
  48. {
  49. _loginFailed?.Invoke("Looks like you have canceled signin with google");
  50. }
  51. else
  52. {
  53. string _token = _task.Result.IdToken;
  54. var _credential = GoogleAuthProvider.GetCredential(_token, null);
  55. _loginSuccess?.Invoke(_credential);
  56. }
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement