salesforce SDK的OAuth刷新令牌流程

时间:2014-11-13 15:52:08

标签: ios salesforce

任何人都可以帮助我在saleforce上刷新令牌。

NSDictionary *fields = @{@"grant_type" : @"refresh_token",
                         @"refresh_token": oauth[@"refreshToken"],
                         @"client_id": coordinator.credentials.clientId,
                         @"format": @"json"
                         };
SFRestRequest *request = [SFRestRequest requestWithMethod:SFRestMethodPOST path:[NSString stringWithFormat:@"%@/services/oauth2/token",[SFAccountManager loginHost]] queryParams:fields];
request.endpoint = [NSString stringWithFormat:@"%@/services/oauth2/authorize", [SFAccountManager loginHost]];

[[SFRestAPI sharedInstance] sendRESTRequest:request failBlock:^(NSError *e) {

    NSLog(@"Error %@", e);

} completeBlock:^(NSDictionary* dict) {

    NSLog(@"dict");

}];

这就是我想要做的,但我收到以下错误:

错误域= NSURLErrorDomain代码= 404"无法完成操作。 (NSURLErrorDomain错误404。)" UserInfo = 0x7993c670 {Transfer-Encoding = Identity,Content-Type = text / html; charset = UTF-8,Date = Thu,2014年11月13日15:23:36 GMT}

我不确定出了什么问题。 仅供参考:Understanding the OAuth Refresh Token Process

这是请求:

endpoint: test.salesforce.com/services/oauth2/authorize 
method: POST 
path: test.salesforce.com/services/oauth2/token 
queryParams: {"grant_type":"refresh_token","refresh_token":"5AsdfdfssdBuiV6yFNukUqDSMUH1tnk39L.x0GFcdqdMhpmQUTu.wv1BNndfglD3SxEZIFUev4i8T2KLkcCOK","format":"json","client_id":"3MVG9dPGzsddfssfdsOQG3p9KW.2hh3Bh5BeEsdfsRlDhxcybG.YRTQC0C0XayvzEw.5.umftLwJpYjYVDE6xgSCgXo"} 

1 个答案:

答案 0 :(得分:0)

我停止使用Salesforce和NSURL Kit,而是使用AFHTTPREQUEST

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setObject:@"password" forKey:@"grant_type"];
    [dict setObject:@"xxx" forKey:@"client_id"];
    [dict setObject:@"xxx" forKey:@"client_secret"];
    [dict setObject:@"your user" forKey:@"username"];
    [dict setObject:@"password" forKey:@"password"];
    [dict setObject:@"json" forKey:@"format"];

[manager POST:@"https://test.salesforce.com/services/oauth2/token" parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSLog(@"JSON: %@", responseObject);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {

    }];