java正在验证应用程序,Amazon Cognito开发人员使用Java SDK验证身份

I am trying to authenticate a java app to AWS services using a developer-authenticated Cognito identity. This is very straightforward in the AWS mobile SDKs (documentation), but I can't seem to find the equivalent classes in the Java SDK.

The main issue I am having is that the Java SDK classes (such as WebIdentityFederationSessionCredentialsProvider) require the client code to know the arn of the role being assumed. With the mobile SDK, it uses the role configured for the federated identity. That's what I'd prefer to do, but it seems the Java SDK doesn't have the supporting classes for that.

解决方案

The last comment from Jeff led me to the answer. Thanks Jeff!

String cognitoIdentityId = "your user's identity id";

String openIdToken = "open id token for the user created on backend";

Map logins = new HashMap<>();

logins.put("cognito-identity.amazonaws.com", openIdToken);

GetCredentialsForIdentityRequest getCredentialsRequest =

new GetCredentialsForIdentityRequest()

.withIdentityId(cognitoIdentityId)

.withLogins(logins);

AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient();

GetCredentialsForIdentityResult getCredentialsResult = cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest);

Credentials credentials = getCredentialsResult.getCredentials();

AWSSessionCredentials sessionCredentials = new BasicSessionCredentials(

credentials.getAccessKeyId(),

credentials.getSecretKey(),

credentials.getSessionToken()

);

AmazonS3Client s3Client = new AmazonS3Client(sessionCredentials);

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值