Salesforce 身份验证失败 [英] Salesforce Authentication Failing

查看:127
本文介绍了Salesforce 身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 OAuth 身份验证来获取 Salesforce 身份验证令牌,因此我参考了

如果您担心禁用安全性,现在不要担心,您只是想让它现在工作,以便您可以进行 API 调用.在一切正常后收紧权限,一次一个,这样您就可以找出导致身份验证错误的设置.


第 10 步:

庆祝!此 curl 调用应该会成功:

生产:

curl -v https://login.salesforce.com/services/oauth2/token \-d "grant_type=password" \-d "client_id=YOUR_CLIENT_ID_FROM_STEP_8" \-d "client_secret=YOUR_CLIENT_SECRET_FROM_STEP_8" \-d "用户名=user@wherever.com" -d "密码=foo@bar.com"

沙盒测试上:

curl -v https://test.salesforce.com/services/oauth2/token \-d "grant_type=password" \-d "client_id=YOUR_CLIENT_ID_FROM_STEP_8" \-d "client_secret=YOUR_CLIENT_SECRET_FROM_STEP_8" \-d "用户名=user@wherever.com" -d "密码=foo@bar.com"

注意事项:

  • 如果您正在构建一个多租户应用程序,那么您不应该进行密码授权,用户需要在其中授权他们自己的应用程序.为此,请使用 Oauth2 工作流程.

  • 您可能需要传递附加到密码的安全令牌.

I am trying to use OAuth authentication to get the Salesforce Authentication Token, so I referred wiki docs, but after getting authorization code, when I make a Post request with 5 required parameters, I'm getting following exception

{"error":"invalid_grant","error_description":"authentication failure"} CODE 400
JSON = {"error":"invalid_grant","error_description":"authentication failure"}

which is I guess a bad request.

PostMethod post = new PostMethod("https://login.salesforce.com/services/oauth2/token");
post.addParameter("code",##############);
post.addParameter("grant_type","authorization_code");
post.addParameter("redirect_uri","#################");  
post.addParameter("client_id",this.client_id);
post.addParameter("client_secret",this.client_secret);
httpclient.executeMethod(post);
String responseBody = post.getResponseBodyAsString();
System.out.println(responseBody+" CODE "+post.getStatusCode());

Kindly reply, if exception known?

解决方案

For anyone who is as stuck and frustrated as I was, I've left a detailed blog post on the entire process (with pictures and ranty commentary!). Click the link if you want that:

http://www.calvinfroedge.com/salesforce-how-to-generate-api-credentials/

Here is a text only answer:

Step 1:

Create an account. You can create a (free) developer account at developer.salesforce.com


Step 2:

Ignore all the landing pages and getting started crap. It's an endless marketing loop.


Step 3:

Click the "Setup" link


Step 4:

In the lefthand toolbar, under "Create", click "Apps"


Step 5:

Under "Connected Apps" click "New"


Step 6:

Fill out the form. Important fields are the ones marked as required, and the oauth section. Note that you can leave any url for your callback (I used localhost).


Step 7:

Be advised that Salesforce has crappy availability.


Step 8:

Press continue. You finally have your client_id key (labelled 'Consumer Key') and client_secret (labelled 'Consumer Secret').


Step 9:

But wait! You're not done yet; select 'Manage' then 'Edit Policies'

  1. Make sure IP relaxation is set to Relax IP restrictions,

  2. and make sure that Permitted Users is set to "All users may self-authorize.",

  3. and also make sure the your Security > Network Access > Trusted IP Ranges has been set

If you're concerned about disabling security, don't be for now, you just want to get this working for now so you can make API calls. Tighten permissions once you have everything working, one at a time, so you can figure out what setting is giving you authentication errors.


Step 10:

Celebrate! This curl call should succeed:

on production:

curl -v https://login.salesforce.com/services/oauth2/token \
  -d "grant_type=password" \
  -d "client_id=YOUR_CLIENT_ID_FROM_STEP_8" \
  -d "client_secret=YOUR_CLIENT_SECRET_FROM_STEP_8" \
  -d "username=user@wherever.com" -d "password=foo@bar.com"

on sandbox or test:

curl -v https://test.salesforce.com/services/oauth2/token \
  -d "grant_type=password" \
  -d "client_id=YOUR_CLIENT_ID_FROM_STEP_8" \
  -d "client_secret=YOUR_CLIENT_SECRET_FROM_STEP_8" \
  -d "username=user@wherever.com" -d "password=foo@bar.com"

Notes:

  • You shouldn't be doing password authorization if you're building a multi-tenant app, where users need to authorize their own application. Use the Oauth2 workflow for that.

  • You may need to pass in your security token appended to your password.

这篇关于Salesforce 身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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