iPhone Objective C oauth 2.0 登录 - unsupported_grant_type [英] iPhone Objective C oauth 2.0 Login - unsupported_grant_type

查看:106
本文介绍了iPhone Objective C oauth 2.0 登录 - unsupported_grant_type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Salesforce 开发的新手,正在尝试连接到 Salesforce 以获取令牌.

I am brand new to salesforce development and am trying to connect to Salesforce to get the token.

我想我的问题有两个:1) 我是否必须使用网页才能向顺丰进行身份验证?

I guess my question is 2 fold: 1) Do I have to use a webpage to authenticate with SF?

2) 如果没有,为什么这不起作用?当我尝试使用用户名和密码进行身份验证时,我得到:{"error":"unsupported_grant_type","error_description":"不支持授权类型"}

2) If not, why is this not working? When I try to use the username and password method of authenticating, I get: {"error":"unsupported_grant_type","error_description":"grant type not supported"}

这是我的代码:

NSString *post = [NSString stringWithFormat:@"grant_type=basic-credentials&client_id=%@&client_secret=%@&redirect_uri=%@",
                  kOAuthClientID,
                  kOAuthClientSecret,
                  kOAuthClientAuthURL
                  ];


NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:kOAuthClientTokenUrl]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];

NSError *error;
NSURLResponse *response;
NSLog(@"%@", request);
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@", data);

欢迎提出任何想法.

我确实尝试过使用 grant_type = authorization_code 但遇到另一个错误:

I did try using grant_type = authorization_code but got another error:

{"error":"invalid_grant","error_description":"无效授权代码"}

{"error":"invalid_grant","error_description":"invalid authorization code"}

推荐答案

如果要使用用户名/密码授权类型,那么它的类型是密码而不是basic-credentials,要发送的正确参数集是

If you want to use the username/password grant type, then its type is password not basic-credentials, the correct set of parameters to send are

grant_type=password
client_id=xxxxxxxxxx
client_secret=1234567890
username=noreply@salesforce.com
password=XXXXXXXXX

正如我在您之前的问题中提到的,虽然这有效,但您确实希望使用基于网络的流程来支持使用 SAML 等替代登录服务的 Salesforce 客户.

As i mentioned in your previous question, although this works, you really do want to use the web based flow so as to support salesforce customers that are using alternative login services like SAML.

这篇关于iPhone Objective C oauth 2.0 登录 - unsupported_grant_type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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