首页 > 解决方案 > 如何使用 Firebase 进行身份验证,在 Android 上使用 Microsoft

问题描述

在 Android 上使用 Microsoft 进行身份验证

最初,我能够进入身份验证页面(请参阅:登录),但是在没有更改代码的情况下,它似乎突然跳过或失败OnSuccessListener,这导致身份验证页面最终失败并让我回到我的主页中MainActivity.java 看到:结果

需要明确的是,我希望我正在使用的应用程序提示 Microsoft 登录,然后在成功/失败时,在那里做一些事情。Firebase Google 登录非常适合我。我觉得问题可能在于我如何将应用程序从 Firebase 重定向到 Azure AD。如果我单击第一个选项(我想要的),它仍然会失败,如果我完全删除我的 URI,我会收到一条错误消息,指出我正在尝试使用错误的应用程序进行身份验证,请参阅:URI

错误:com.google.firebase.auth.firebaseAuthInvalidCredentialsException: The supplied auth credential is malformed or has expired. [Error getting access token from microsoft.com...] 我的应用程序 ID、机密和重定向 URI都与我在 Azure AD 中的内容匹配。错误

        firebaseAuth
        .startActivityForSignInWithProvider(/* activity= */ this, provider.build())
        .addOnSuccessListener(
            new OnSuccessListener<AuthResult>() {
            @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("Successfully authenticated with Microsoft.");
                microsoftSignOutButton.setVisibility(microsoftSignOutButton.VISIBLE);
            }
        })
        .addOnFailureListener(
            new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                // Handle failure.
                statusTextView.setText("Failed to load on Microsoft sign in.");
            }
        });

标签: androidfirebasefirebase-authentication

解决方案


推荐阅读