0

我们正在尝试在我们的 android 和 iOS 应用程序中实施 AWS Security Token Service。在后端,我们使用以下代码生成令牌:

public class CloudManagementImpl implements CloudManagement{

    private static final Logger Log = LoggerFactory.getLogger(CloudManagementImpl.class);

    @Override
    public CloudConfiguration getCloudProperties() {

        CloudConfiguration CloudConfiguration = new CloudConfiguration();

        AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest();
        assumeRoleRequest.setRoleArn(JiveGlobals.getProperty(XYZConstant.AWS_ARN_EC2_ROLE_MAP));
        assumeRoleRequest.setRoleSessionName(XYZConstant.AWS_ROLE_SESSIONNAME);
        assumeRoleRequest.setDurationSeconds(JiveGlobals.getIntProperty(XYZConstant.AWS_CREDENTIALS_LIFETIME, 1800));

        AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient();
        AssumeRoleResult assumeRoleResult = stsClient.assumeRole(assumeRoleRequest);
        if (assumeRoleResult != null) {
            Credentials sessionCredentials = assumeRoleResult.getCredentials();
            CloudConfiguration.setAwsAccessId(sessionCredentials.getAccessKeyId());
            CloudConfiguration.setAwsAccessKey(sessionCredentials.getSecretAccessKey());
            CloudConfiguration.setToken(sessionCredentials.getSessionToken());
            CloudConfiguration.setAwsMainBucket(JiveGlobals.getProperty(XYZConstant.AWS_MAIN_BUCKET));
        } else {
            Log.error("Cloud Management :: Propery values not configured ");
        }

        return CloudConfiguration;
    }

}

然后通过单独的 Web 服务调用在 iOS 和 android 应用程序中获取生成的令牌。

在 android 中,我们使用以下代码来使用检索到的令牌:

public S3Client(String accessKey, String secretKey, String token, String bucketName) {
        super();
        this.accessKey = accessKey;
        this.secretKey = secretKey;
        this.bucketName = bucketName;
        BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(accessKey, secretKey, token);
        amazonS3Client = new AmazonS3Client(basicSessionCredentials);

    }

问题是——

我们在适用于 iOS 的 AWS 移动 SDK 版本 2 中没有类似 android 的 API,我们可以使用它来使用检索到的令牌,也许在 iOS 中实现此功能的最佳方法是通过 AWSCognitoCredentialsProvider,但我们不确定。

请建议 - 在 iOS 中集成 AWS Security Token Service 的最佳方式是什么。

4

1 回答 1

2

您需要通过符合AWSCredentialsProvider. 听起来您已经有一个代码片段可以从您的服务器检索临时凭据。该逻辑应该进入您的自定义凭据提供程序。您可以查看实现AWSWebIdentityCredentialsProvider以及AWSCognitoCredentialsProvider如何实现您自己的凭据提供程序。

于 2014-09-30T17:11:25.757 回答