【发布时间】:2019-09-01 16:18:07
【问题描述】:
您好,我是 android 应用程序开发人员,我正在为移动应用程序使用 cognito 身份验证机制。一旦我验证了我的用户,我就会得到RefreshToken 和IDToken。根据 Amazon cognito 的说法,它会在一小时后过期 IDToken。我正在尝试再次获取我的会话以再次获取令牌,这就是我尝试完成它的方法。
String poolId = 'xxxxxx';
String clientId = 'xxxxxx';
String clientSecret = 'xxxxxx';
CognitoUserPool userPool = new CognitoUserPool(context, poolId, clientId, clientSecret,Regions.EU_WEST_1);
CognitoUser user = userPool.getUser();
user.getSessionInBackground(new AuthenticationHandler() {
@Override
public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
String idToken = userSession.getIdToken().getJWTToken();
Map<String, String> logins = new HashMap<String, String>();
logins.put("cognito-idp." + Constants.REGION + ".amazonaws.com/" + Constants.UserPool, userSession.getIdToken().getJWTToken());
credentialsProvider.setLogins(logins);
credentialsProvider.refresh();
}
@Override
public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
Log.i("MQTT","Detail");
}
@Override
public void getMFACode(MultiFactorAuthenticationContinuation continuation) {
Log.i("MQTT","MFACode");
}
@Override
public void authenticationChallenge(ChallengeContinuation continuation) {
Log.i("MQTT","Challenge");
}
@Override
public void onFailure(Exception exception) {
Log.i("MQTT","Fail");
}
});
我有userpoolid,需要知道从哪里可以获得clientID 和clientSecret。这样我才能在onSuccess 回调中获取数据并获得IDToken。
如果有人能帮忙,真的很感激。 谢谢
【问题讨论】:
标签: android authentication amazon-cognito refresh-token