title: How to get Access Token after authenticating from google firebase in Xamarin android app in c#?
body: <p>I am working in Xamarin android app in c# with google firebase authentication. The code is working fine with firebase. it is authenticating the user while login and returning the name and email address. But I need the <strong><em>access token</em></strong> after authentication in firebase , to work further with REST API. but I am unable to get the <strong><em>access token</em></strong> , can I get the access token?</p>
  
  <p>Code is as follows:</p>
  
  <pre><code>using Android.App;
  using Android.OS;
  using Android.Support.V7.App;
  using Android.Runtime;
  using Android.Widget;
  using Android.Gms.Auth.Api.SignIn;
  using Android.Gms.Common.Apis;
  using Android.Gms.Auth.Api;
  using Firebase.Auth;
  using Firebase;
  using Android.Content;
  using System;
  using Android.Gms.Tasks;
  using Java.Lang;
  
  
  namespace loginGoogle
  {
      [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
      public class MainActivity : AppCompatActivity, IOnSuccessListener, IOnFailureListener, IOnCompleteListener
      {
          GoogleSignInOptions gso;
          GoogleApiClient googleApiClient;
  
          FirebaseAuth firebaseAuth;
          Button signinButton;
          protected override void OnCreate(Bundle savedInstanceState)
          {
              base.OnCreate(savedInstanceState);
  
              // Set our view from the "main" layout resource
              SetContentView(Resource.Layout.activity_main);
  
              signinButton = (Button)FindViewById(Resource.Id.signInButton);
  
              signinButton.Click += SigninButton_Click;
  
              gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                  .RequestIdToken("759281956917-ib3rko81uvs4bvdf3g3p76f0dl7q8k64.apps.googleusercontent.com")
                  .RequestEmail()
                  .Build();
  
              googleApiClient = new GoogleApiClient.Builder(this)
                  .AddApi(Auth.GOOGLE_SIGN_IN_API, gso).Build();
              googleApiClient.Connect();
  
              firebaseAuth = GetFirebaseAuth();
              UpdateUI();
          }
  
  
          private FirebaseAuth GetFirebaseAuth()
          {
              var app = FirebaseApp.InitializeApp(this);
              FirebaseAuth mAuth;
  
              if (app == null)
              {
                  var options = new FirebaseOptions.Builder()
                      .SetProjectId("login-bde5d")
                      .SetApplicationId("login-bde5d")
                      .SetApiKey("AIzaSyCql6njOSplLxy6Nd2tpNHNSeBxyOm6TQM")
                      .SetDatabaseUrl("https://login-bde5d.firebaseio.com")
                      .SetStorageBucket("login-bde5d.appspot.com")
                      .Build();
  
                  app = FirebaseApp.InitializeApp(this, options);
                  mAuth = FirebaseAuth.Instance;
  
              }
              else
              {
                  mAuth = FirebaseAuth.Instance;
              }
              return mAuth;
          }
          private void SigninButton_Click(object sender, System.EventArgs e)
          {
              UpdateUI();
              if (firebaseAuth.CurrentUser == null)
              {
                  var intent = Auth.GoogleSignInApi.GetSignInIntent(googleApiClient);
                  StartActivityForResult(intent, 1);
              }
              else
              {
                  firebaseAuth.SignOut();
                  UpdateUI();
              }
          }
  
          protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
          {
              base.OnActivityResult(requestCode, resultCode, data);
  
              if (requestCode == 1)
              {
                  GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                  if (result.IsSuccess)
                  {
                      GoogleSignInAccount account = result.SignInAccount;
                      LoginWithFirebase(account);
                  }
              }
          }
  
          private void LoginWithFirebase(GoogleSignInAccount account)
          {
              var credentials = GoogleAuthProvider.GetCredential(account.IdToken, null);
              firebaseAuth.SignInWithCredential(credentials).AddOnSuccessListener(this)
                  .AddOnFailureListener(this).AddOnCompleteListener(this, this);
          }
  
          public void OnSuccess(Java.Lang.Object result)
          {            
              TextView displayNameText = (TextView)FindViewById(Resource.Id.displaynameText);
              TextView emailText = (TextView)FindViewById(Resource.Id.emailText);
  
              displayNameText.Text = "Display Name: " + firebaseAuth.CurrentUser.DisplayName;
              emailText.Text = "Email: " + firebaseAuth.CurrentUser.Email;            
  
              Toast.MakeText(this, "Login successful", ToastLength.Short).Show();
              UpdateUI();
          }
  
          public void OnFailure(Java.Lang.Exception e)
          {
              Toast.MakeText(this, "Login Failed", ToastLength.Short).Show();
              UpdateUI();
          }
          void UpdateUI()
          {
              if (firebaseAuth.CurrentUser != null)
              {
                  signinButton.Text = "Sign Out";
              }
              else
              {
                  signinButton.Text = "Sign In With Google";
              }
          }
  
          public void OnComplete(Task task)
          {
              //throw new NotImplementedException();
              if (task.IsSuccessful)
              {                
                  TextView photourlText = (TextView)FindViewById(Resource.Id.photoURLText);
                  photourlText.Text = "User successfully login with Photo URL: " + firebaseAuth.CurrentUser.PhotoUrl.Path;
  
              }
              else
              {
                  TextView photourlText = (TextView)FindViewById(Resource.Id.photoURLText);
                  photourlText.Text = "problem in user login";
              }
          }
      }
  }
  </code></pre>
  
  <p>I have followed the following link:
  <a href="https://www.youtube.com/watch?v=NYMCrD9klA0" rel="nofollow noreferrer">https://www.youtube.com/watch?v=NYMCrD9klA0</a></p>