title: How to Authenticate with Firebase, Using Microsoft on Android
body: <p><a href="https://firebase.google.com/docs/auth/android/microsoft-oauth" rel="nofollow noreferrer">Authenticate Using Microsoft on Android</a></p>
  <p>Originally, I was able to get to the auth page (see: <a href="https://i.stack.imgur.com/VdvfA.png" rel="nofollow noreferrer">login</a>), but then with no changes to the code, it seems to suddenly skip or fail at the <code>OnSuccessListener</code> function, which results in the auth page eventually failing and bringing me back to my home page in <code>MainActivity.java</code> <a href="https://i.stack.imgur.com/4lRbI.png" rel="nofollow noreferrer">see: result</a>.</p>
  <p>To be clear, I want the app I'm working with, to prompt a Microsoft sign-in and then upon success/failure, do something there. The Firebase Google-sign in works perfectly for me. I have a feeling that the problem may lie with how I'm redirecting the app from Firebase to Azure AD. If I click the first option (which I want), it still fails, and if I remove my URI entirely, I get an error message saying that I'm trying to authenticate with the wrong app <a href="https://i.stack.imgur.com/eAYZs.png" rel="nofollow noreferrer">see: URI</a>.</p>
  <p>ERROR: <code>com.google.firebase.auth.firebaseAuthInvalidCredentialsException: The supplied auth credential is malformed or has expired. [Error getting access token from microsoft.com...]</code> <a href="https://i.stack.imgur.com/tfndP.png" rel="nofollow noreferrer">My app id, secret and redirect URI</a> all match what I have in my Azure AD. <a href="https://i.stack.imgur.com/sGCWP.png" rel="nofollow noreferrer">ERROR</a></p>
  <pre><code>        firebaseAuth
          .startActivityForSignInWithProvider(/* activity= */ this, provider.build())
          .addOnSuccessListener(
              new OnSuccessListener&lt;AuthResult&gt;() {
              @Override
              public void onSuccess(AuthResult authResult) {
                  // User is signed in.
                  // IdP data available in
                  // authResult.getAdditionalUserInfo().getProfile().
                  // The OAuth access token can also be retrieved:
                  // authResult.getCredential().getAccessToken().
                  // The OAuth ID token can also be retrieved:
                  // authResult.getCredential().getIdToken().
                 // openActivity2();
                  statusTextView.setText(&quot;Successfully authenticated with Microsoft.&quot;);
                  microsoftSignOutButton.setVisibility(microsoftSignOutButton.VISIBLE);
              }
          })
          .addOnFailureListener(
              new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                  // Handle failure.
                  statusTextView.setText(&quot;Failed to load on Microsoft sign in.&quot;);
              }
          });
  </code></pre>