AWS Cognito:"此身份池不支持未经身份验证的访问。"

时间:2017-02-13 15:27:31

标签: ios swift amazon-web-services amazon-cognito aws-mobilehub

我正在使用我的Swift iOS应用程序中的AWS Cognito处理问题"Unauthenticated access is not supported for this identity pool."。我之前使用Firebase进行身份验证和存储并已决定迁移到AWS Mobile Hud,原因超出了本问题的范围。

我使用/设置了:

  1. 亚马逊移动Hud提供所有服务
  2. 通过移动Hud进行身份验证/身份的AWS Cognito
  3. Facebook已作为身份提供商激活
  4. 在控制台中激活AWS DynamoDB但尚未使用
  5. AWS S3在控制台中激活但尚未使用
  6. 我下载了为我的项目生成的示例应用并运行它。

      

    通过示例应用程序,我能够通过Facebook和Cognito成功注册/验证。

    什么有用?:我已将AWS的所有SDK /框架集成到我的项目中并能够成功构建(注意:所有AWS框架都是通过cocoapod集成的,除了' AWSMobileHubHelper&# 39;作为静态框架)。

      

    我可以构建应用程序并打开

    什么不起作用?:使用以下崩溃日志打开后应用程序立即崩溃:

    2017-02-13 15:43:49.825 dates[19823:463495] AWSiOSSDK v2.5.0 [Debug] AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
    {
        Connection = "keep-alive";
        "Content-Length" = 111;
        "Content-Type" = "application/x-amz-json-1.1";
        Date = "Mon, 13 Feb 2017 14:43:49 GMT";
        "x-amzn-ErrorMessage" = "Unauthenticated access is not supported for this identity pool.";
        "x-amzn-ErrorType" = "NotAuthorizedException:";
        "x-amzn-RequestId" = "d4f8ec82-f1fa-11e6-bd81-3727ca129d86";
    }
    2017-02-13 15:43:49.826 dates[19823:463495] AWSiOSSDK v2.5.0 [Debug] AWSURLResponseSerialization.m line:63 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body:
    {"__type":"NotAuthorizedException","message":"Unauthenticated access is not supported for this identity pool."}
    2017-02-13 15:43:49.826 dates[19823:463495] AWSiOSSDK v2.5.0 [Error] AWSIdentityProvider.m line:309 | __52-[AWSCognitoCredentialsProviderHelper getIdentityId]_block_invoke.255 | GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}]
    2017-02-13 15:43:49.826 dates[19823:463452] AWSiOSSDK v2.5.0 [Error] AWSCredentialsProvider.m line:565 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.349 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Unauthenticated access is not supported for this identity pool.}]
    2017-02-13 15:43:49.827 dates[19823:463379] -[AWSTask exception]: unrecognized selector sent to instance 0x60800027af00
    2017-02-13 15:43:49.828 dates[19823:463379] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AWSTask exception]: unrecognized selector sent to instance 0x60800027af00'
    *** First throw call stack:
    (
        0   CoreFoundation                      0x0000000112abcd4b __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x000000011251e21e objc_exception_throw + 48
        2   CoreFoundation                      0x0000000112b2cf04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
        3   CoreFoundation                      0x0000000112a42005 ___forwarding___ + 1013
        4   CoreFoundation                      0x0000000112a41b88 _CF_forwarding_prep_0 + 120
        5   dates                               0x000000010ef4e917 __35-[AWSIdentityManager completeLogin]_block_invoke_2 + 263
        6   libdispatch.dylib                   0x00000001150f4978 _dispatch_call_block_and_release + 12
        7   libdispatch.dylib                   0x000000011511e0cd _dispatch_client_callout + 8
        8   libdispatch.dylib                   0x00000001150fe8a4 _dispatch_main_queue_callback_4CF + 406
        9   CoreFoundation                      0x0000000112a80e49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
        10  CoreFoundation                      0x0000000112a4637d __CFRunLoopRun + 2205
        11  CoreFoundation                      0x0000000112a45884 CFRunLoopRunSpecific + 420
        12  GraphicsServices                    0x0000000116249a6f GSEventRunModal + 161
        13  UIKit                               0x0000000112ee0c68 UIApplicationMain + 159
        14  dates                               0x000000010edac89f main + 111
        15  libdyld.dylib                       0x000000011516a68d start + 1
        16  ???                                 0x0000000000000001 0x0 + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    

    我尝试了什么?

    1. 将我的代码与示例应用进行比较:结果 - 据我所知,1:1匹配
    2. 将Info.plist与示例应用进行比较:结果 - 1:1匹配(我复制了相关部分)
    3. 删除所有框架,清理,重建
    4. 清理所有模拟器数据(由另一个类似的问题引用)
    5. 尝试了相关问题的方法:(检查未经身份验证的访问权限)
    6. 如果我允许未经身份验证的访问会发生什么?:相同,但响应标头不同:(

      2017-02-13 16:25:06.213 dates[25642:544704] AWSiOSSDK v2.5.0 [Debug] AWSURLSessionManager.m line:566 | -[AWSURLSessionManager printHTTPHeadersForResponse:] | Response headers:
      {
          Connection = "keep-alive";
          "Content-Length" = 1612;
          "Content-Type" = "application/x-amz-json-1.1";
          Date = "Mon, 13 Feb 2017 15:25:05 GMT";
          "x-amzn-RequestId" = "98feb58d-f200-11e6-9de9-471b5799b768";
      }
      2017-02-13 16:25:06.213 dates[25642:544704] AWSiOSSDK v2.5.0 [Debug] AWSURLResponseSerialization.m line:63 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body:
      {"Credentials":{"AccessKeyId":"ASIAISM6BUQFY6FJ4EFQ","Expiration":1.487003106E9,"SecretKey":"rlILMNjU7oeg1NEYgj1y3E1v/5L3IOJNWtZ7jsOf","SessionToken":"AgoGb3JpZ2luEFMaCWV1LXdlc3QtMSKAAgM0QlWyWW3xJ0H3+suiuuekGl6LUznBSikSWbYgLD9C6nPywAyKIlI5EVSN0q7o80q30ZWX8KE/Yjwo+axii1v/A2Qz9gqXWz4HRFwaJnHLE46nNLSJNNkNUhMkYy+azMCdKnZteUEtBzvHcWAVsyqAHtRSzKjGimXfs8WXs7d14g0GabTm73qj7tvOa4Facnetc9aUZjyLLKBsy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5uvC1q1c3tnF/j/cIVzMqGobPfY25BftoZq6azFvaL/jXIGIDaUT9os0WR0mWybmCCd9Gwo25zsw0p+HxQU="},"IdentityId":"eu-west-1:a9ef3c7f-8be8-411c-9249-48df6f04f4ac"}
      2017-02-13 16:25:06.220 dates[25642:544675] -[AWSTask exception]: unrecognized selector sent to instance 0x6180002656c0
      2017-02-13 16:25:06.222 dates[25642:544675] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AWSTask exception]: unrecognized selector sent to instance 0x6180002656c0'
      *** First throw call stack:
      (
          0   CoreFoundation                      0x000000010ff21d4b __exceptionPreprocess + 171
          1   libobjc.A.dylib                     0x000000010f98321e objc_exception_throw + 48
          2   CoreFoundation                      0x000000010ff91f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
          3   CoreFoundation                      0x000000010fea7005 ___forwarding___ + 1013
          4   CoreFoundation                      0x000000010fea6b88 _CF_forwarding_prep_0 + 120
          5   dates                               0x000000010c43d917 __35-[AWSIdentityManager completeLogin]_block_invoke_2 + 263
          6   libdispatch.dylib                   0x0000000112559978 _dispatch_call_block_and_release + 12
          7   libdispatch.dylib                   0x00000001125830cd _dispatch_client_callout + 8
          8   libdispatch.dylib                   0x00000001125638a4 _dispatch_main_queue_callback_4CF + 406
          9   CoreFoundation                      0x000000010fee5e49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
          10  CoreFoundation                      0x000000010feab37d __CFRunLoopRun + 2205
          11  CoreFoundation                      0x000000010feaa884 CFRunLoopRunSpecific + 420
          12  GraphicsServices                    0x00000001136aea6f GSEventRunModal + 161
          13  UIKit                               0x0000000110345c68 UIApplicationMain + 159
          14  dates                               0x000000010c29b89f main + 111
          15  libdyld.dylib                       0x00000001125cf68d start + 1
          16  ???                                 0x0000000000000001 0x0 + 1
      )
      libc++abi.dylib: terminating with uncaught exception of type NSException
      

      我越是看它,这似乎是AWSTask的一个问题。

      我可能会接下来的任何想法吗?

2 个答案:

答案 0 :(得分:0)

要通过AWSCognitoIdentityUserPoolConfiguration返回此问题而无法访问,我正在探索启用未经身份验证的访问权限。

执行此操作时,App Delegate会运行并获取未经授权的访问权限。然后,在用户注册中,将在Login ViewController中使用Sign In API,然后获取AWS凭据以进行身份​​验证访问。

这允许我们(如果需要)访问DynamoDB,Lambda,同时等待用户第一次登录。我们可以通过为经过身份验证和未经身份验证的用户设置正确的策略来控制应用程序必须访问的内容。

这个文档虽然很简单,却有迄今为止我发现的最好的Swift示例。

http://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

进入下一步!

答案 1 :(得分:-1)

AWS通过Swift 3支持更新解决了该问题。