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 を使用することですが、よくわかりません。

提案してください - AWS Security Token Service を iOS に統合する最良の方法は何ですか?

4

1 に答える 1

2

に準拠して、独自の認証情報プロバイダーを実装する必要がありますAWSCredentialsProvider。サーバーから一時的な資格情報を取得するコード スニペットが既にあるようです。そのロジックは、カスタム資格情報プロバイダーに入る必要があります。独自の資格情報プロバイダーを実装する方法については、実装を参照してAWSWebIdentityCredentialsProviderください。AWSCognitoCredentialsProvider

于 2014-09-30T17:11:25.757 に答える