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這些令牌?或者還有其他方法。
在此先感謝。