Cognito认证工作,但错误说明了什么? [英] Cognito Authentication working but errors show?

查看:833
本文介绍了Cognito认证工作,但错误说明了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我使用的是开发验证的身份到我的用户进行身份验证。尽管这个错误显示:


  

AWSiOSSDKv2 [详细] AWSURLResponseSerialization.m行:87 |
   - [AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:数据:错误:]
  |响应体:
  [{__type:抛出:InvalidParameterException,消息:请提供
  有效的公共提供商}] 2015年10月20日17:50:19.251
  占用时间[56549:7365231] AWSiOSSDKv2 [错误] AWSCredentialsProvider.m
  行:435 | __73- [AWSCognitoCredentialsProvider
  getCredentialsWithCognito:验证:] _ block_invoke |
  GetCredentialsForIdentity失败。错误是[错误
  域名= com.amazonaws.AWSCognitoIdentityErrorDomain code = 7的
  操作无法完成。
  (com.amazonaws.AWSCognitoIdentityErrorDomain错误七)
  的UserInfo = {0x7f9d9342dde0 = __type抛出:InvalidParameterException,
  消息=请提供有效的公共提供商}]


虽然这个错误显示,我还是回我identityId和令牌,并成功调用,需要经过身份验证的权限调用一个lambda方法。我相信这是与我的刷新方法,但我不能完全肯定。请帮我处理这个错误。

我的凭据提供code:

  * NSUserDefaults的默认值= [NSUserDefaults的standardUserDefaults]    [AWSLogger defaultLogger] .logLevel = AWSLogLevelVerbose;
    ID< AWSCognitoIdentityProvider> identityProvider = [[BusytimeAuthenticated页头] initWithRegionType:AWSRegionUSEast1
                                                                                             identityId:无
                                                                                         identityPoolId:@EXAMPLEPOOLID
                                                                                登录:@ {@login.busytimeapp:[默认objectForKey:@用户名]}
                                                                                           的providerName:@login.busytimeapp
                                                       ];    credentialsProvider = [[AWSCognitoCredentialsProvider页头] initWithRegionType:AWSRegionUSEast1
                                                                   identityProvider:identityProvider
                                                                      unauthRoleArn:无
                                                                        authRoleArn:无];    配置= [[AWSServiceConfiguration页头] initWithRegion:AWSRegionUSEast1
                                                credentialsProvider:self.credentialsProvider];
    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration =配置;
    [credentialsProvider刷新] continueWithBlock:^ ID(BFTask *任务){
        [个体经营testAuth]
        回零;
    }];

我的刷新方式:

   - (BFTask *){刷新
    * NSUserDefaults的默认值= [NSUserDefaults的standardUserDefaults]
    如果(![个体经营authenticatedWithProvider]){
        返回[超级getIdentityId]
    }其他{
        *的NSDictionary后= [[NSDictionary的页头] initWithObjectsAndKeys:
                              [默认objectForKey:@用户名],@用户名,
                              [默认objectForKey:@密码],@密码
                              零];
        NSError *错误;
        NSData的* POSTDATA = [NSJSONSerialization dataWithJSONObject:后继选项:0错误:&放大器;错误]
        * NSString的postLength = [的NSString stringWithFormat:@%吕氏春秋,(无符号长)POSTDATA长度]];
        NSMutableURLRequest *请求= [[NSMutableURLRequest的alloc]初始化];
        [要求setURL:[NSURL URLWithString:@SOMEURL]];
        [要求setHTTPMethod:@POST];
        [申请的setValue:postLength forHTTPHeaderField:@内容长度];
        [要求setHTTPBody:POSTDATA];
        NSURLSession *会话= [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
        __block BOOL isLogged = FALSE;
        [会议dataTaskWithRequest:请求completionHandler:^(NSData的*数据,NSURLResponse *响应,NSError *错误){
            *的NSDictionary = newJSON [NSJSONSerialization JSONObjectWithData:数据
                                                                    选项​​:0
                                                                      错误:&放大器;错误]
            isLogged = TRUE;
            如果(!newJSON){
                的NSLog(@未验证);
            }其他{            self.identityId = [newJSON objectForKey:@IdentityId];
            self.token = [newJSON objectForKey:@令牌];
            的NSLog(@结果:%@,newJSON);
            }        }] 简历];        返回[超级getIdentityId]    }
    返回[超级getIdentityId]
}


解决方案

这里的问题是,你在登录映射的关键传球登录提供程序名称。你不能这样做,对于开发者验证的身份。

相反,你应该使用Cognito身份提供者的名称, cognito-identity.amazonaws.com 的,在地图上,像它说,在的文档。这应该可以解决你例外。

Basically I'm using a developer authenticated identity to authenticate my users. Even though this error is showing:

AWSiOSSDKv2 [Verbose] AWSURLResponseSerialization.m line:87 | -[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body: [{"__type":"InvalidParameterException","message":"Please provide a valid public provider"}] 2015-10-20 17:50:19.251 BusyTime[56549:7365231] AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:435 | __73-[AWSCognitoCredentialsProvider getCredentialsWithCognito:authenticated:]_block_invoke | GetCredentialsForIdentity failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=7 "The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 7.)" UserInfo=0x7f9d9342dde0 {__type=InvalidParameterException, message=Please provide a valid public provider}]

Though this error shows, I'm still returning my identityId and Token and successfully invoking a lambda method that requires authenticated privileges to call. I believe it has something to do with my refresh method but I'm not exactly sure. Please help me deal with this error.

my credentials provider code:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;
    id<AWSCognitoIdentityProvider> identityProvider = [[BusytimeAuthenticated alloc] initWithRegionType:AWSRegionUSEast1
                                                                                             identityId:nil
                                                                                         identityPoolId:@"EXAMPLEPOOLID"
                                                                                logins:@{@"login.busytimeapp": [defaults objectForKey:@"username"]}
                                                                                           providerName:@"login.busytimeapp"
                                                       ];

    credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
                                                                   identityProvider:identityProvider
                                                                      unauthRoleArn:nil
                                                                        authRoleArn:nil];

    configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
                                                credentialsProvider:self.credentialsProvider];
    AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;
    [[credentialsProvider refresh] continueWithBlock:^id(BFTask *task){
        [self testAuth];
        return nil;
    }];

My Refresh method:

- (BFTask *)refresh {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (![self authenticatedWithProvider]) {
        return [super getIdentityId];
    }else{
        NSDictionary *post = [[NSDictionary alloc] initWithObjectsAndKeys:
                              [defaults objectForKey:@"username"], @"username",
                              [defaults objectForKey:@"password"], @"password",
                              nil];
        NSError *error;
        NSData *postData = [NSJSONSerialization dataWithJSONObject:post options:0 error:&error];
        NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:[NSURL URLWithString:@"SOMEURL"]];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setHTTPBody:postData];
        NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
        __block BOOL isLogged = false;
        [[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            NSDictionary *newJSON = [NSJSONSerialization JSONObjectWithData:data
                                                                    options:0
                                                                      error:&error];
            isLogged = true;
            if(!newJSON){
                NSLog(@"DID NOT AUTHENTICATE");
            }else{

            self.identityId = [newJSON objectForKey:@"IdentityId" ];
            self.token = [newJSON objectForKey:@"Token" ];
            NSLog(@"Result: %@", newJSON);
            }

        }] resume];

        return [super getIdentityId];

    }
    return [super getIdentityId];
}

解决方案

The problem here is that you are passing the login provider name in the logins map as key. You can't do that for Developer Authenticated Identities.

Instead you should use the Cognito identity provider name, cognito-identity.amazonaws.com, in the map, like it says in the documentation. This should fix you exception.

这篇关于Cognito认证工作,但错误说明了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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