0

AWS Cognito API を使用して Swift で作成された iOS アプリがあります。USEast1 への接続は期待どおりに機能し、ユーザーを認証します

var awsProperties = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("AWS", ofType: "plist")!)
var credentialsProvider : AWSCognitoCredentialsProvider
var loggedIn = false

override init() {
    credentialsProvider  = AWSCognitoCredentialsProvider.credentialsWithRegionType(
        AWSRegionType.USEast1,
        accountId:awsProperties?.valueForKey(GlobalConstants.AccountId) as String,
        identityPoolId:awsProperties?.valueForKey(GlobalConstants.USIdentityPoolId) as String,
        unauthRoleArn:awsProperties?.valueForKey(GlobalConstants.UnauthDefaultRole) as String,
        authRoleArn:awsProperties?.valueForKey(GlobalConstants.AuthDefaultRole) as String)
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
    let defaultServiceConfiguration = AWSServiceConfiguration(
        region: AWSRegionType.USEast1,
        credentialsProvider: credentialsProvider)
    AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(defaultServiceConfiguration)
    credentialsProvider.getIdentityId().continueWithBlock { (task: BFTask!) -> AnyObject! in
        if((task.error) != nil) {
            NSLog("%@", task.error)
        } else {
            NSLog("%@", self.credentialsProvider.identityId)
            self.loggedIn = true
        }
        return self.loggedIn
    }

    return true
}

別のログイン コントローラーで G+ に対するログインを許可するために必要なコードがあり、地域固有のものはありません。

ただし、まったく同じコードを使用し、リージョンを EUWest1 に変更し、EU ベースの識別プールを使用すると、次の例外が発生します。

AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:453 | __46-[AWSCognitoCredentialsProvider getIdentityId]_block_invoke | In refresh, but identityId is nil.
AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:454 | __46-[AWSCognitoCredentialsProvider getIdentityId]_block_invoke | Result from getIdentityId is (null)

私の IAM ロールの信頼ポリシーは、両方の ID プールへのアクセスを許可します。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Federated": "accounts.google.com"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "cognito-identity.amazonaws.com:aud": [
            "eu-west-1:XXXXXX",
            "us-east-1:XXXXXX"
          ]
        },
        "ForAnyValue:StringLike": {
          "cognito-identity.amazonaws.com:amr": "authenticated"
        }
      }
    }
  ]
}

リージョンをオーバーライドする必要がある場所がありませんか?

4

1 に答える 1

0

通常、これに数日間苦労した後、最終的にSOに投稿した問題を理解しました。

問題は、AWS iOS SDK の以前のバージョンが Framework Search Paths にリンクされていて、EUCentral1 がなかったことです。それを列挙に含めることでインデックスが変更されたようであり、Cognito が USEast1 と EUWest1 でのみサポートされていることを考えると、Cognito は正しくないリージョンに対して認証を試みていました。

于 2015-01-03T15:14:26.707 に答える