• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FirebaseAuthUserCollisionException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.firebase.auth.FirebaseAuthUserCollisionException的典型用法代码示例。如果您正苦于以下问题:Java FirebaseAuthUserCollisionException类的具体用法?Java FirebaseAuthUserCollisionException怎么用?Java FirebaseAuthUserCollisionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FirebaseAuthUserCollisionException类属于com.google.firebase.auth包,在下文中一共展示了FirebaseAuthUserCollisionException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: signIn

import com.google.firebase.auth.FirebaseAuthUserCollisionException; //导入依赖的package包/类
protected void signIn(AuthCredential credential) {
    mAuth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (!task.isSuccessful()) {
                Exception exception = task.getException();
                if (exception != null) {
                    String errorText;
                    if (exception instanceof FirebaseAuthUserCollisionException) {
                        errorText = getString(R.string.error_user_collision);
                    } else {
                        errorText = exception.toString();
                    }
                    errorTV.setText(errorText);
                    errorTV.setVisibility(View.VISIBLE);
                }
                LoginManager.getInstance().logOut();
            }
        }
    });
}
 
开发者ID:vycius,项目名称:NMAkademija,代码行数:22,代码来源:StartActivity.java


示例2: onComplete

import com.google.firebase.auth.FirebaseAuthUserCollisionException; //导入依赖的package包/类
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
    if (task.isSuccessful()) {
        FirebaseUser firebaseUser = task.getResult().getUser();
        mActivity.saveCredentialsOrFinish(mSmartLock, firebaseUser, mResponse);
    } else {
        if (task.getException() instanceof FirebaseAuthUserCollisionException) {
            String email = mResponse.getEmail();
            if (email != null) {
                FirebaseAuth auth = mActivity.getAuthHelper().getFirebaseAuth();
                ProviderUtils.fetchTopProvider(auth, email)
                        .addOnSuccessListener(new StartWelcomeBackFlow())
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                Intent intent = IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR);
                                mActivity.finish(Activity.RESULT_CANCELED, intent);
                            }
                        });
                return;
            }
        } else {
            Log.e(TAG,
                  "Unexpected exception when signing in with credential "
                          + mResponse.getProviderType()
                          + " unsuccessful. Visit https://console.firebase.google.com to enable it.",
                  task.getException());
        }

        mActivity.getDialogHolder().dismissDialog();
    }
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:33,代码来源:CredentialSignInHandler.java


示例3: testSignInFailed_withFacebookAlreadyLinked

import com.google.firebase.auth.FirebaseAuthUserCollisionException; //导入依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testSignInFailed_withFacebookAlreadyLinked() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    IdpResponse idpResponse =
            new IdpResponse.Builder(
                    new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL)
                            .build())
                    .setToken(TestConstants.TOKEN)
                    .build();
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
            mockActivity,
            null,
            RC_ACCOUNT_LINK,
            idpResponse);

    FlowParameters mockFlowParams = mock(FlowParameters.class);
    when(mockActivity.getFlowParams()).thenReturn(mockFlowParams);

    AuthHelper mockAuthHelper = mock(AuthHelper.class);
    when(mockActivity.getAuthHelper()).thenReturn(mockAuthHelper);
    AuthHelperShadow.getFirebaseAuth(); // Force static initialization
    when(mockAuthHelper.getFirebaseAuth()).thenReturn(AuthHelperShadow.getFirebaseAuth());

    ProgressDialogHolder mockHolder = mock(ProgressDialogHolder.class);
    when(mockActivity.getDialogHolder()).thenReturn(mockHolder);

    // pretend the account has Facebook linked already
    when(AuthHelperShadow.getFirebaseAuth().fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(
            new AutoCompleteTask<ProviderQueryResult>(
                    new FakeProviderQueryResult(
                            Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null));

    // pretend there was already an account with this email
    Task<AuthResult> exceptionTask = Tasks.forException(
            new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
    credentialSignInHandler.onComplete(exceptionTask);
    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
    verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
    Intent capturedIntent = intentCaptor.getValue();
    User capturedUser = User.getUser(capturedIntent);
    assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
    assertEquals(
            WelcomeBackIdpPrompt.class.getName(),
            capturedIntent.getComponent().getClassName());
    assertEquals(
            TestConstants.EMAIL,
            capturedUser.getEmail());
    assertEquals(
            FacebookAuthProvider.PROVIDER_ID,
            capturedUser.getProviderId());

}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:55,代码来源:CredentialSignInHandlerTest.java


示例4: testSignInFailed_withPasswordAccountAlreadyLinked

import com.google.firebase.auth.FirebaseAuthUserCollisionException; //导入依赖的package包/类
@Test
@Config(shadows = {AuthHelperShadow.class})
public void testSignInFailed_withPasswordAccountAlreadyLinked() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    IdpResponse idpResponse =
            new IdpResponse.Builder(
                    new User.Builder(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL)
                            .build())
                    .setToken(TestConstants.TOKEN)
                    .build();
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(
            mockActivity,
            null,
            RC_ACCOUNT_LINK,
            idpResponse);

    FlowParameters mockFlowParams = mock(FlowParameters.class);
    when(mockActivity.getFlowParams()).thenReturn(mockFlowParams);

    AuthHelper mockAuthHelper = mock(AuthHelper.class);
    when(mockActivity.getAuthHelper()).thenReturn(mockAuthHelper);
    AuthHelperShadow.getFirebaseAuth(); // Force static initialization
    when(mockAuthHelper.getFirebaseAuth()).thenReturn(AuthHelperShadow.getFirebaseAuth());

    ProgressDialogHolder mockHolder = mock(ProgressDialogHolder.class);
    when(mockActivity.getDialogHolder()).thenReturn(mockHolder);

    // pretend there was already an account with this email
    Task mockTask = mock(Task.class);
    when(mockTask.getException()).thenReturn(
            new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));

    // pretend the account has a Password account linked already
    when(AuthHelperShadow.getFirebaseAuth().fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(
            new AutoCompleteTask<ProviderQueryResult>(
                    new FakeProviderQueryResult(
                            Arrays.asList(EmailAuthProvider.PROVIDER_ID)), true, null));


    credentialSignInHandler.onComplete(mockTask);
    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
    verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
    Intent capturedIntent = intentCaptor.getValue();
    assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
    assertEquals(
            WelcomeBackPasswordPrompt.class.getName(),
            capturedIntent.getComponent().getClassName());
    assertEquals(
            TestConstants.EMAIL,
            IdpResponse.fromResultIntent(capturedIntent).getEmail());
}
 
开发者ID:firebase,项目名称:FirebaseUI-Android,代码行数:53,代码来源:CredentialSignInHandlerTest.java



注:本文中的com.google.firebase.auth.FirebaseAuthUserCollisionException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SpoutSpec类代码示例发布时间:2022-05-22
下一篇:
Java NameNodeHttpServer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap