【发布时间】:2017-12-24 03:31:54
【问题描述】:
我需要以经过身份验证的用户身份将文件上传到 S3。我已经设法从 CognitoUserPool 作为 CognitoUser 获取令牌。
这里是代码。
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 中吗?或者有没有其他办法。
提前致谢。
【问题讨论】:
-
有人能解释一下我如何获得 clientSecret 吗?
标签: android amazon-web-services amazon-s3 amazon-cognito