我目前正在使用 AWS STS 访问 S3 资源。我第一次能够在 STS 凭证的帮助下使用 get 对象访问 S3 资源。15 分钟后,我使用 getAssumeRoleForUser 获得了新凭证。这次我是由于令牌过期异常,无法访问 S3 资源。以下是用于遵循上述过程的代码。
类 CustomIdentityProvider: NSObject, AWSCredentialsProvider{ var token:String! var awsAccessKey:字符串!var awsSecretKey:字符串!var awsExpiration: NSDate! var awsRegion:字符串!功能凭证()-> AWSTask{
let credentials = AWSCredentials(accessKey:self.awsAccessKey,
secretKey:self.awsSecretKey, sessionKey :self.token,
expiration:self.awsExpiration as! Date)
return AWSTask(result:credentials)
}
func invalidateCachedTemporaryCredentials() {
print("cache clear")
}
init(accessKey: String, secretKey: String, sessionKey: String?, expiration:
NSDate?) {
self.token = sessionKey
self.awsAccessKey = accessKey
self.awsSecretKey = secretKey
self.awsExpiration = expiration
} }
//Implementations
let expirationTime = m.expiration
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = dateFormatter.date(from: expirationTime )
let awsExpiration = date as NSDate?
let customProviderManager = CustomIdentityProvider(accessKey:
m.accessKeyId ?? "", secretKey: m.secretAccessKey ?? "", sessionKey:
m.sessionToken ?? "", expiration: awsExpiration)
let serviceConfig = AWSServiceConfiguration(region: AWSRegionType.APSouth1,
credentialsProvider: customProviderManager)
AWSServiceManager.default().defaultServiceConfiguration =
serviceConfig
请让我知道处理此令牌过期问题需要什么。让我知道我这边是否还有其他设置或代码丢失。在 Android 中一切正常