Ios Google OAuth突然无法在NetworkingErrorDomain上工作

Ios Google OAuth突然无法在NetworkingErrorDomain上工作,ios,oauth,google-oauth,Ios,Oauth,Google Oauth,在过去的一周里,我的iOS应用程序的GoogleOAuth部分突然完全停止了工作。用户将其详细信息输入应用程序内的自定义登录字段,然后通过谷歌授权,创建令牌,并应告诉他们登录已成功(在应用程序内)。相反,他们看到的是登录失败的消息。我似乎不明白为什么(谷歌改变了什么吗??),但当用户尝试登录时,我得到的错误代码如下: 2013-10-27 12:49:56.137 XXXX [1210:1a003] URL is https://accounts.google.com/o/oau

在过去的一周里,我的iOS应用程序的GoogleOAuth部分突然完全停止了工作。用户将其详细信息输入应用程序内的自定义登录字段,然后通过谷歌授权,创建令牌,并应告诉他们登录已成功(在应用程序内)。相反,他们看到的是登录失败的消息。我似乎不明白为什么(谷歌改变了什么吗??),但当用户尝试登录时,我得到的错误代码如下:

        2013-10-27 12:49:56.137 XXXX [1210:1a003] URL is https://accounts.google.com/o/oauth2/approval?as=1e543c0fe20b1da5&hl=en_GB&pageId=none&xsrfsign=APsBz4gAAAAAUm1LHD2mXAhs8QexAFwlf9KVIt5UdNj_
    2013-10-27 12:49:57.776 XXXX[1210:1a003] 333
    2013-10-27 12:49:57.776 XXXX[1210:1a003] Failed: -1011
    2013-10-27 12:49:57.777 XXXX[1210:1a003] Description: Error
Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 400" 
UserInfo=0x96b5700 {NSLocalizedRecoverySuggestion=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 
4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Google 
Accounts</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta 
name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-
scale=1, user-scalable=0" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><link 
rel='stylesheet' type='text/css' href='https://ssl.gstatic.com/accounts/o/1893590695-error_page_css_ltr.css'>
    <script type="text/javascript" src="https://ssl.gstatic.com/accounts/o/708588620-common_lib.js"></script>
    <style>@media screen and (max-width:500px) {#robot {background: none; min-height: 0; min-width: 0; padding: 0;}#stack_trace {display: none;}}
    #oauth2_request_info_header {background-image: url("https://ssl.gstatic.com/accounts/o/blank.gif");}</style></head><body ><div id="robot"></div><a href="//www.google.com/" id="googlelogo"><img src="//www.google.com/images/logo_sm.gif" alt="Google"></a><p class="large"><b>400.</b> <ins>That's an error.</ins></p><p class="large">The page that you requested is invalid.  <ins>That's all we know.</ins></p></body></html>, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest https://accounts.google.com/o/oauth2/approval?as=1e543c0fe20b1da5&hl=en_GB&pageId=none&xsrfsign=APsBz4gAAAAAUm1LHD2mXAhs8QexAFwlf9KVIt5UdNj_>, NSErrorFailingURLKey=https://accounts.google.com/o/oauth2/approval?as=1e543c0fe20b1da5&hl=en_GB&pageId=none&xsrfsign=APsBz4gAAAAAUm1LHD2mXAhs8QexAFwlf9KVIt5UdNj_, NSLocalizedDescription=Expected status code in (200-299), got 400, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x96aae40>}
2013-10-27 12:49:56.137 XXXX[1210:1a003]URL为https://accounts.google.com/o/oauth2/approval?as=1e543c0fe20b1da5&hl=en_GB&pageId=none&xsrfsign=APsBz4gAAAAAUm1LHD2mXAhs8QexAFwlf9KVIt5UdNj_
2013-10-27 12:49:57.776 XXXX[1210:1a003]333
2013-10-27 12:49:57.776 XXXX[1210:1a003]失败:-1011
2013-10-27 12:49:57.777 XXXX[1210:1a003]说明:错误
Domain=AFNetworkingErrorDomain Code=-1011“预期状态代码为(200-299),获得400”
UserInfo=0x96b5700{nsLocalizedRecoverysSuggestion=Google
账户
@媒体屏幕和(最大宽度:500px){#机器人{背景:无;最小高度:0;最小宽度:0;填充:0;}#堆栈{跟踪{显示:无;}
#oauth2_请求_信息_头{背景图像:url(“https://ssl.gstatic.com/accounts/o/blank.gif);}

400。这是一个错误。

您请求的页面无效。我们只知道这些。

,AFNetworkingOperationFailingURLRequestErrorKey=,NSErrorFailingURLKey==https://accounts.google.com/o/oauth2/approval?as=1e543c0fe20b1da5&hl=en_GB&pageId=none&xsrfsign=APsBz4gAAAAAUm1LHD2mXAhs8QexAFwlf9KVIt5UdNj_,NSLocalizedDescription=中的预期状态代码(200-299),获得400,AFNetworkingOperationFailingURLResponseErrorKey=}
以下是导致错误的代码部分:

-(void)doSignInStep2:(NSString*)response
{
   // NSLog(@"RESPONSE: %@", response);

    NSString *form = [response substringFromIndex:[response rangeOfString:@"form "].location];
    form = [form substringToIndex:[form rangeOfString:@"</form>"].location];

    NSString *formAction = [form substringFromIndex:[form rangeOfString:@"action="].location + 8];
    formAction = [formAction substringToIndex:[formAction rangeOfString:@"\""].location];

    if ([formAction rangeOfString:@"'"].location != NSNotFound)
    {
        formAction = [formAction substringToIndex:[formAction rangeOfString:@"'"].location];
    }


    formAction = [formAction stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];

    //get all input elements in the form
    NSMutableArray *elements = [[NSMutableArray alloc] init];

    NSRange rng = [form rangeOfString:@"<input "];

    while (rng.location != NSNotFound)
    {
        NSString *inputItem = [form substringFromIndex:rng.location];
        NSInteger *inputItemLength = [inputItem rangeOfString:@">"].location + 1;
        inputItem = [inputItem substringToIndex:inputItemLength];

        NSString *elementName = nil;
        NSString *elementValue = nil;

        NSRange iiRange = [inputItem rangeOfString:@"name=\""];

        if (iiRange.location != NSNotFound) {
            elementName = [inputItem substringFromIndex:iiRange.location + 6];
            elementName = [elementName substringToIndex:[elementName rangeOfString:@"\""].location];
        }

        iiRange = [inputItem rangeOfString:@"value=\""];

        if (iiRange.location != NSNotFound) {
            elementValue = [inputItem substringFromIndex:iiRange.location + 7];
            elementValue = [elementValue substringToIndex:[elementValue rangeOfString:@"\""].location];

            elementValue = [elementValue stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
        }

        if (elementName && elementValue) {
            NSString *encodedstring = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
                                                                                                   (__bridge CFStringRef)elementValue,
                                                                                                   NULL,
                                                                                                   (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                                                   kCFStringEncodingUTF8);

            if (![elementName isEqualToString:@"submit_access"])
                [elements addObject:[NSMutableArray arrayWithObjects:elementName, encodedstring, nil]];
        }

        form = [form substringFromIndex:rng.location];

        form = [form substringFromIndex:inputItemLength];

        rng = [form rangeOfString:@"<input "];
    }

    [elements addObject:[NSMutableArray arrayWithObjects:@"submit_access", @"true", nil]];


    NSString *params = @"";

    for (int i = 0; i < [elements count]; i++)
    {
        NSMutableArray *element = [elements objectAtIndex:i];

        if ([params length] > 0)
            params = [params stringByAppendingString:@"&"];

        params = [params stringByAppendingString:[element objectAtIndex:0]];
        params = [params stringByAppendingString:@"="];
        params = [params stringByAppendingString:[element objectAtIndex:1]];
    }

    //NSLog(@"Params: %@", params);

    NSURL *url = [NSURL URLWithString:formAction];
    NSLog(@"URL is %@", url);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
    //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    //[request setValue:[params length] forHTTPHeaderField:@"Content-Length"];

    AFHTTPRequestOperation *op3 = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    [op3 setCompletionBlockWithSuccess:  ^(AFHTTPRequestOperation *operation, NSError *error) {
        NSString *response = [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding];

        [self doSignInStep3:response];


    }failure: ^(AFHTTPRequestOperation *operation, NSError *error)
     {
         NSLog(@"333");
         NSLog(@"Failed: %d", error.code);
         NSLog(@"Description: %@", error.description);

         //NSLog(@"Response: %@", [[NSString alloc] initWithData:operation.responseData encoding:NSUTF8StringEncoding]);


         [self.delegate finishedSignIn:[NSNumber numberWithBool:NO] response:nil];
     }];

    [op3 start];

}
-(void)dosinstep2:(NSString*)响应
{
//NSLog(@“响应:%@”,响应);
NSString*form=[response substringFromIndex:[response rangeOfString:@“form”]。位置];
form=[form substringToIndex:[form rangeOfString:@'].location];
NSString*formAction=[form substringFromIndex:[form rangeOfString:@“action=“]”。位置+8];
formAction=[formAction substringToIndex:[formAction rangeOfString:@“\”]。位置];
if([formAction rangeOfString:@“']”。位置!=NSNotFound)
{
formAction=[formAction substringToIndex:[formAction rangeOfString:@“'”。位置];
}
formAction=[formAction StringByReplacingOfString:@“&;“with String:@”&;“with String:@”];
//获取表单中的所有输入元素
NSMutableArray*元素=[[NSMutableArray alloc]init];
NSRange rng=[格式rangeOfString:@”“]。位置+1;
inputItem=[inputItem substringToIndex:inputItemLength];
NSString*elementName=nil;
NSString*elementValue=nil;
NSRange iiRange=[inputItem rangeOfString:@“name=\”;
if(iiRange.location!=NSNotFound){
elementName=[inputItem substringFromIndex:iiRange.location+6];
elementName=[elementName substringToIndex:[elementName rangeOfString:@“\”。位置];
}
iiRange=[inputItem rangeOfString:@“value=\”;
if(iiRange.location!=NSNotFound){
elementValue=[inputItem substringFromIndex:iiRange.location+7];
elementValue=[elementValue substringToIndex:[elementValue rangeOfString:@“\”。位置];
elementValue=[elementValue StringByReplacingOfString:@“&;“withString:@”&;“withString:@”&];
}
if(elementName&&elementValue){
NSString*encodedstring=(uu桥NSString*)CFURLCreateStringByAddingPercents转义(NULL,
(_桥CFStringRef)元素值,
无效的
(CFStringRef)@“!*”();:@&=+$,/?%#[],
kCFStringEncodingUTF8);
如果(![elementName IsequalString:@“提交访问权限”])
[elements addObject:[NSMutableArray arrayWithObjects:elementName,encodedstring,nil]];
}
form=[form substringfromfromindex:rng.location];
form=[form substringFromIndex:inputItemLength];

rng=[form rangeOfString:@”查看日志中包含的错误页面,我明白了

The page that you requested is invalid. That's all we know.
我的应用程序是一个Web服务器应用程序,但我经常在授权过程中看到相同的错误页面。在我的情况下,我只是返回并重试

我的工作假设是,这是谷歌基础设施中某个地方抛出的一个暂时性异常,它在一条误导性/无意义的错误消息中实现

因此,对于你的应用程序,我只能建议你以某种方式捕捉这种情况,然后重试登录

The page that you requested is invalid. That's all we know.