iPhone Objective C oauth 2.0 登录

编程入门 行业动态 更新时间:2024-10-24 20:18:13
本文介绍了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 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 登录

本文发布于:2023-10-12 16:43:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Objective   iPhone   oauth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!