2017-07-19 16 views
0

認証されたユーザーとしてファイルをS3にアップロードする必要があります。私はCognitoUserPoolからトークンをCognitoUserとして取得しました。Android - 認証されたユーザーのためのCognitoCachingCredentialsProviderの方法

ここにコードがあります。

String poolId = "xxxxxxxxxxx"; 
    String clientId = "xxxxxxxxxxx"; 
    String clientSecret = "xxxxxxxxxxxx"; 

// Create a CognitoUserPool object to refer to your user pool 
CognitoUserPool userPool = new CognitoUserPool(getApplicationContext(), poolId, clientId, clientSecret,Regions.XX_XXXX_X); 

CognitoUser user = userPool.getUser(); 

user.getSessionInBackground(authenticationHandler); 

以下がAuthenticationHandlerコールバックです。

final AuthenticationHandler authenticationHandler = new 
AuthenticationHandler() { 

     @Override 
     public void onSuccess(CognitoUserSession cognitoUserSession, CognitoDevice cognitoDevice) { 

      Log.d("success",cognitoUserSession.getAccessToken().getJWTToken()); 

     } 

     @Override 
     public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) { 
      // The API needs user sign-in credentials to continue 
      AuthenticationDetails authenticationDetails = new AuthenticationDetails("test", "test", null); 

      // Pass the user sign-in credentials to the continuation 
      authenticationContinuation.setAuthenticationDetails(authenticationDetails); 

      // Allow the sign-in to continue 
      authenticationContinuation.continueTask(); 
     } 

     ... 


     @Override 
     public void onFailure(Exception exception) { 
      // Sign-in failed, check exception for the cause 
      Log.d("Error here",exception.toString()); 
     } 
    }; 

これらのトークンをSharedPereferenceに自分で保存すると思いますか?または他の方法の周りにあります。

ありがとうございます。

答えて

0

あなたのアイデンティティプールを持つユーザー・プールのユーザーをリンクするためのプロセスは、ここで説明されていますhttp://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

cognitoUser.getSessionInBackground(new AuthenticationHandler() { 
    @Override 
    public void onSuccess(CognitoUserSession session) { 
     String idToken = session.getIdToken().getJWTToken(); 

     Map<String, String> logins = new HashMap<String, String>(); 
     logins.put(cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>, session.getIdToken().getJWTToken()); 
     credentialsProvider.setLogins(logins); 
     credentialsProvider.refresh(); 
    } 

});

関連する問題