2016-04-19 17 views
0

Facebookでユーザーを認証し、AWS Cognitoで単一の新しいIDを作成する際に問題があります。そのユーザーがアプリを削除して再ダウンロードした場合、Cognitoは同じIDを返すようにします。Android FacebookログインAWS Cognito

Facebookログインは動作しますが、credentialsProvider.setLogins(logins);毎回4つの新しい認証されていないアイデンティティを作成します。

final CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(getApplicationContext(), "xxxxxxxx", Regions.US_EAST_1); 

    loginButton = (LoginButton) findViewById(R.id.login_button); 
    loginButton.setReadPermissions(Arrays.asList("email", "user_friends")); 

    callbackManager = CallbackManager.Factory.create(); 

    accessTokenTracker = new AccessTokenTracker() { 
     @Override 
     protected void onCurrentAccessTokenChanged(
       AccessToken oldAccessToken, 
       AccessToken currentAccessToken) { 
      updateWithToken(currentAccessToken); 

     } 
    }; 

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) { 

      Map<String, String> logins = new HashMap<String, String>(); 
      logins.put("graph.facebook.com", AccessToken.getCurrentAccessToken().getToken()); 
      credentialsProvider.setLogins(logins); 
      Log.d("LogTag", "my ID is " + logins); 
     } 


     @Override 
     public void onCancel() { 
      Toast.makeText(getBaseContext(), "Login Cancelled", Toast.LENGTH_SHORT).show(); 
      Log.v("LoginActivity", "cancel"); 
     } 

     @Override 
     public void onError(FacebookException exception) { 
      Toast.makeText(getBaseContext(), "Problem connecting to Facebook", Toast.LENGTH_SHORT).show(); 
      Log.v("LoginActivity", exception.getCause().toString()); 
     } 
    }); 

} 

private void updateWithToken(AccessToken token) { 
    if (token != null) { 

     Intent intent = new Intent(LogIn.this, NavDrawer.class); 
     LogIn.this.startActivity(intent); 

    } 
    ; 
} 

@Override 
public void onDestroy() { 
    super.onDestroy(); 
    accessTokenTracker.stopTracking(); 
} 

@Override 
protected void onResumeFragments() { 
    super.onResumeFragments(); 
    updateWithToken(AccessToken.getCurrentAccessToken()); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    callbackManager.onActivityResult(requestCode, resultCode, data); 
    Intent intent = new Intent(LogIn.this, Buffer.class); 
    LogIn.this.startActivity(intent); 
} 

}

すべてのヘルプは素晴らしいだろう、あなたのおかげで!

答えて

0

Facebookからのアクセストークンが更新されるたびに新しいアクティビティが開始されています。つまり、毎回異なるCognitoCachingCredentialsProviderのインスタンスを作成していますが、これは正しくありません。

理想的には、CognitoCachingCredentialsProviderをアプリケーションでシングルトンとして使用し、すべてのアクティビティとアプリケーションロジックで使用する必要があります。フローのモデル化の例としてCognito sample applicationを使用することができます。

関連する問題