在进行POST方法调用时,我需要访问令牌作为标头传递。我正在尝试获取如下访问令牌。
@Override
protected Void doInBackground(Void... voids) {
AmazonCognitoIdentityProviderClient identityProviderClient = new AmazonCognitoIdentityProviderClient(new AnonymousAWSCredentials(), new ClientConfiguration());
identityProviderClient.setRegion(Region.getRegion(Regions.SOMETHING));
final CognitoUserPool userPool = new CognitoUserPool(context,
poolId,
clientId, null, identityProviderClient);
final CognitoUser cognitoUser = userPool.getCurrentUser();
System.out.println(cognitoUser.getUserId());
final AuthenticationHandler authenticationHandler = new AuthenticationHandler() {
@Override
public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
Log.i("ACCESS_TOKEN", userSession.getIdToken().getJWTToken());
}
}
cognitoUser.getSession(authenticationHandler);
}
我总是将访问令牌设为null。我的代码有什么错误?