AWS Cognito集成swift3 Refresh提供ResourceNotFoundException [英] AWS Cognito integration swift3 Refresh provides ResourceNotFoundException

查看:123
本文介绍了AWS Cognito集成swift3 Refresh提供ResourceNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此处遵循答案:
https://github.com / aws / aws-sdk-ios / issues / 357
在最底部,有一个快速入门和认知工作的迷你指南。

Following the answer here: https://github.com/aws/aws-sdk-ios/issues/357 At the very bottom there is a mini guide on getting swift and cognito working.

我已经这样制作了一个AWSCustomIdentityProvider:

I've made a AWSCustomIdentityProvider as such:

import Foundation
import AWSCognitoIdentityProvider
import AWSCognito

class AWSCustomIdentityProvider: NSObject, AWSIdentityProviderManager
{

private var dict = NSDictionary()

func addToken(value:NSString)
{
    dict = ["graph.facebook.com":value]
}

public func logins() -> AWSTask<NSDictionary>
{
    return AWSTask(result: dict)
}
}

我有一个来自Facebook的登录方法:

And I have a login method from facebook:

public func loginButtonDidCompleteLogin(_ loginButton: FacebookLogin.LoginButton, result: FacebookLogin.LoginResult){

    switch result {
    case .failed(let error):
        print("FACEBOOK LOGIN FAILED: \(error)")
    case .cancelled:
        print("User cancelled login.")
    case .success(_, _, let accessToken):


        let customIdentity = AWSCustomIdentityProvider()
        let token = accessToken.authenticationToken
        customIdentity.addToken(value: token as NSString)

        let credentialsProvider = AWSCognitoCredentialsProvider(regionType: REGIONTYPE, identityPoolId: "XXXXXXXXXXXXXXXXXXXXXXX", identityProviderManager:customIdentity)

        credentialsProvider.clearKeychain()
        credentialsProvider.clearCredentials()

        let serviceConfiguration = AWSServiceConfiguration(region: REDIONTYPE, credentialsProvider: credentialsProvider)
        AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration;

        credentialsProvider.getIdentityId().continue( { (task: AWSTask!) -> AnyObject! in
            if (task.error != nil) {
                print("Error: " + (task.error?.localizedDescription)!)// gets called
            }
            else {
                print(task.result)//identityid
            }
            return nil
        })
    }
}

但是我得到错误:


Error Domain = com.amazonaws.AWSCognitoIdentityErrorDomain Code = 8(null) UserInfo = {__ type = NotAuthorizedException,message =登录名不匹配。请为此身份或身份池至少包含一个有效的登录名。}

Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8 "(null)" UserInfo={__type=NotAuthorizedException, message=Logins don't match. Please include at least one valid login for this identity or identity pool.}

如果您有任何想法,请告诉我解决我的问题。我也尝试过遵循文档并直接设置登录名 credentialsProvider.logins = { graph.facebook.com:mytoken}

Please let me know if you have any idea on how to resolve my issue. I've tried also following the docs and setting the logins directly "credentialsProvider.logins = {"graph.facebook.com": mytoken}

,这会产生不同的异常

在调用lambda方法后,确实可以正确检索identityID,但是根据文档进行操作会警告我使用的方法已弃用。得到:

The error I get:


UserInfo = {NSLocalizedDescription = serialized对象既不是有效的json对象,也不是NSData对象:}

UserInfo={NSLocalizedDescription=serialized object is neither a valid json Object nor NSData object: }

但是有时只发生这种情况。如果我重试,我可能会获得身份ID,但是在调用lambda方法时,会出现相同的错误。

However that only happens sometimes. If I retry then i can potentially get the identity id but upon invoking a lambda method, I get the same error. I'm assuming it is a cognito issue.

更新

如果我使用AWSCognitoLoginProviderKey.facebook。在第一部分中,使用rawValue而不是graph.facebook.com,然后它为我提供了认知ID,然后调用了lambda方法,其中包括lambda方法只是为了防备这是我弄错的部分,但我很确定这是阻止我调用lambda方法的认知:

If I use AWSCognitoLoginProviderKey.facebook.rawValue instead of graph.facebook.com in the first part, then it gives me the cognito ID and then I invoke the lambda method. I'll include the lambda method just incase that's the part I'm getting wrong but I'm decently sure that it's cognito that is preventing me from calling the lambda method:

import AWSLambda
import Foundation
struct AWSHelper{
let lambda = AWSLambda.default()
let APPLICATION_NAME = "MYAPPLICATION"
init(){

}

func getFunctionName(funcName: String) -> String{
    return "\(funcName)_\(APPLICATION_NAME)"
}

func login(facebookID: String, cognitoID:String, callback:@escaping (Bool) -> Void){
    let req = AWSLambdaInvocationRequest();
    req?.invocationType = AWSLambdaInvocationType.requestResponse
    req?.payload = ["cognitoID" : cognitoID, "facebookID" : facebookID]
    req?.functionName = getFunctionName(funcName: "MYFUNCNAME")

    lambda.invoke(req!) { (response: AWSLambdaInvocationResponse?,error: Error?) in
        print(error)
        let payload = response?.payload
        print(payload)
        callback(true)
    }

}
}

更新2

我发现调用这样的刷新方法:

I have found out that calling a refresh method like this:

credentialsProvider.credentials().continue({ (task: AWSTask!) -> Any? in
            print(task.result)
        })

导致如下错误:


AWSiOSSDK v2.4.10 [错误] AWSCredentialsProvider.m行:577 | __44- [AWSCognitoCredentialsProvider凭据] _block_invoke.352 |无法刷新。错误为[错误域= com.amazonaws.AWSCognitoIdentityErrorDomain代码= 10(null) UserInfo = {__ type = ResourceNotFoundException,消息=未找到身份'us-east-1:0db18266-1baa-4c59-9110-f9041dc92ead'。} ]

AWSiOSSDK v2.4.10 [Error] AWSCredentialsProvider.m line:577 | __44-[AWSCognitoCredentialsProvider credentials]_block_invoke.352 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=Identity 'us-east-1:0db18266-1baa-4c59-9110-f9041dc92ead' not found.}]

我相信,看起来像identitypoolID的大字符串实际上是我拥有的给定用户的identityID,因此,cognito已分发ID,但无法查询?

I believe the big string that looks like an identitypoolID is actually the identityID for the given user that I have, so cognito has distributed an ID but is not able to query it?

推荐答案

我认为一些使它起作用的东西。

Few things that made it work I think.

我通过创建自己的identityprovidermanager采取了正确的行动,并且我认为阻碍我执行lambda方法的主要原因实际上是我在使用AWSLambda AWSLambdaInvoker。切换后,它开始产生有意义的错误。

I made the correct move by making my own identityprovidermanager and I think the main thing that was blocking me from executing a lambda method was actually the fact that I was using AWSLambda instead of AWSLambdaInvoker. After I switched it started making errors that made sense.

这篇关于AWS Cognito集成swift3 Refresh提供ResourceNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆