AWSognito обменивает токен на учетные данные в быстром темпе

Я пытаюсь получить доступ к службам aws с помощью пула удостоверений после входа в этот документ aws https://docs.aws.amazon.com/en_us/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pool.html

но при интеграции пользовательского пула с частью Identity Pool я не могу добавить токен в быстрый код

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: nil)
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET", poolId: "YOUR_USER_POOL_ID")
AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "UserPool")
let pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YOUR_IDENTITY_POOL_ID", identityProviderManager:pool)

В javascript и android есть credentialsProvider.logins.

я получил такое сообщение:

Message: The security token included in the request is invalid.

или мне нужно вызвать aws sts api с помощью этого документа? https://docs.aws.amazon.com/en_us/IAM/latest/UserGuide/id_credentials_temp_request.html

Спасибо за помощь.


person saint    schedule 27.02.2019    source источник


Ответы (1)


сначала я попробую это

let identity = AWSCognitoIdentity.default()
        let input = AWSCognitoIdentityGetCredentialsForIdentityInput()
        input?.identityId = identityid
        input?.logins = ["cognito-idp.us-east-1.amazonaws.com/us-east-1_XXXXX":identityToken]
        identity.getCredentialsForIdentity(input!).continueWith(block: { (task:AWSTask<AWSCognitoIdentityGetCredentialsForIdentityResponse>) -> Any? in

            if (task.error != nil) {
                print("Error: " + task.error!.localizedDescription)
            }
            else {
                self.accessKey = (task.result?.credentials?.accessKeyId)!
                self.secrectKey = (task.result?.credentials?.secretKey)!
                self.sessionToken = (task.result?.credentials?.sessionToken)
            }
            return task;
        })

но это не работает, я не уверен, что случилось. Я использую https для получения тени aws iot, он вернет нулевое значение и получит сообщение 403. затем я меняю официальный код документа следующим образом

let serviceConfiguration = AWSServiceConfiguration(region: .USEast1,credentialsProvider: nil)
let userPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: "YOUR_CLIENT_ID", clientSecret: "YOUR_CLIENT_SECRET", poolId: "YOUR_USER_POOL_ID")
AWSCognitoIdentityUserPool.registerCognitoIdentityUserPoolWithConfiguration(serviceConfiguration, userPoolConfiguration: userPoolConfiguration, forKey: "UserPool")
let pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YOUR_IDENTITY_POOL_ID", identityProviderManager:pool)

затем используйте этот код

    credentialsProvider.credentials().continueWith(block: { (task) -> AnyObject? in
        if (task.error != nil) {
            print("Error: " + task.error!.localizedDescription)
        }
        else {
            let credentials = task.result!
            self.accessKey = credentials.accessKey
            self.secrectKey = credentials.secretKey
            self.session  = credentials.sessionKey!           }
        return task;
    })

но этот код не использует idtoken, который я получил при входе в систему с когнитивным доступом, возможно, это просто позволило мне получить доступ к сервису, тогда я могу проанализировать idtoken, чтобы получить подробное сообщение idtoken.

надеюсь, это кому-то поможет.

В дополнение к этому, импортные вещи заключаются в том, чтобы прикрепить к вам временные учетные данные с помощью iotPrincipalPolicy, когда вы входите в систему с когнитивным доступом, вы получите идентификатор идентификатора учетных данных, а затем используете этот идентификатор для присоединения.

или вы получите 403 запрещенных и нулевое возвращаемое значение.

FYR https://github.com/awslabs/aws-sdk-ios-samples/blob/master/IoT-Sample/Swift/IoTSampleSwift/ConnectionViewController.swift

person saint    schedule 07.03.2019