2016-06-15 4 views
0

영어 불어로 죄송합니다.FireBase Auth 다중 인증 시스템 결합

나는 AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); FacebookAuthProvider.getCredential(token.getToken());

내가 중포 기지 문서에서이 걸릴 다음 2 가지 방법

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); 
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 
    mAuth.signInWithCredential(credential) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); 

        // If sign in fails, display a message to the user. If sign in succeeds 
        // the auth state listener will be notified and logic to handle the 
        // signed in user can be handled in the listener. 
        if (!task.isSuccessful()) { 
         Log.w(TAG, "signInWithCredential", task.getException()); 
         Toast.makeText(MainActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); 
        } 
       } 
      }); 
} 

private void firebaseAuthWithFacebook(AccessToken token) { 
    Log.d(TAG, "handleFacebookAccessToken:" + token); 
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); 
    mAuth.signInWithCredential(credential) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); 
        // If sign in fails, display a message to the user. If sign in succeeds 
        // the auth state listener will be notified and logic to handle the 
        // signed in user can be handled in the listener. 
        if (!task.isSuccessful()) { 
         Log.w(TAG, "signInWithCredential", task.getException()); 
         Toast.makeText(MainActivity.this, "Authentication failed.", 
           Toast.LENGTH_SHORT).show(); 
        } 

        // ... 
       } 
      }); 
} 

만이 라인의 변화를 결합하려는.

나는 안드로이드 프로그래머 (나는 약간의 C# 게임 개발자)에서 새로운데, 나를 비난하지 않아.

그리고 나는 이것을 enderstind하지 않습니다 https://firebase.google.com/docs/auth/android/account-linking#link-auth-provider-credentials-to-a-user-account

내가 도움을받을 수 있습니다하세요?

감사합니다.

답변

0

당신은 두 매개 변수의 ACCT를 추가하고 하나의 방법으로 토큰을 한 다음 사용자가이 요청 코드가 있음을 확인하는 것이 페이스 북이 주어 사용하여 로그인해야 null 인 그들 각각이 private void firebaseAuth(GoogleSignInAccount acct,AccessToken token) .If의 ACCT 같은 null 경우 확인하실 수 있습니다 당신이 로그인 할 때 하나의 당신은 OnActivityResult(int requestCode, int resultCode, Intent data) 구글을 사용하여 제공하고 있으므로이 같은 어떤 것을 할 수있는 FacebookCallback<LoginResult>()onSuccess() 방법에서 AccessToken을 통과하면 Auth.GoogleSignInApi.getSignInResultFromIntent(data)에서 얻은 결과는 페이스 북에 대한 result.isSuccess() .Same입니다 :

CallbackManager mCallbackManager = CallbackManager.Factory.create(); 
     LoginManager.getInstance().registerCallback(mCallbackManager, 
       new FacebookCallback<LoginResult>() { 
      @Override 
      public void onSuccess(LoginResult loginResult) { 
       Log.d(TAG, "facebook:onSuccess:" + loginResult); 

       firebaseAuth(null,loginResult.getAccessToken); 
       //null here is the google account as you sign in using facebook    
      } 

      @Override 
      public void onCancel() { 
       //Something to do with user cancel login 
      } 

      @Override 
      public void onError(FacebookException error) { 
       //Something to do with FacebookException 
      } 
     }); 

및 Google의 경우 로그인 :

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 
     if (requestCode == GOOGLE_SIGN_IN) { 

     /* request code you pass to 
     * startActivityForResult(intent, GOOGLE_SIGN_IN) 
     * where intent is what you get from intent = 
     * Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient) 
     */ 

     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);  

      if (result.isSuccess()) { 
       // Google Sign In was successful, authenticate with Firebase 
       GoogleSignInAccount account = result.getSignInAccount(); 
       firebaseAuth(account,null); 
       /* null here is the facebook token 
       * as you sign in using Google 
       */ 

      } else if(result.getStatus().isInterrupted()){ 
       // Google Sign In failed, update UI appropriately 
      } 

     } 
}