Salesforce OAuth 身份验证不适用于用户名和密码 [英] Salesforce OAuth authentication doesnt work with username and password

查看:93
本文介绍了Salesforce OAuth 身份验证不适用于用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我在 salesforce 中创建了一个新的连接应用
  • 我正在尝试使用用户名和密码进行身份验证 - OAuth 方法使用 Postman 获取令牌
  • 我正在访问以下端点 https://login.salesforce.com/services/oauth2/令牌带有我的client_id、client_secret、用户名和密码
  • 我收到以下错误:{错误":invalid_grant","error_description": "身份验证失败"}

  • I created a new connected app in salesforce
  • I am trying to authenticate using username and password - OAuth method to fetch a token using Postman
  • I am hitting the following endpoint https://login.salesforce.com/services/oauth2/token with my client_id, client_secret, username and password
  • I am getting the following error: { "error": "invalid_grant", "error_description": "authentication failure" }

独立验证用户名和密码正确

The username and password are verified to be correct independently

我在这里遗漏了什么?

推荐答案

如果您使用用户名和密码 OAuth 身份验证,请确保您已将唯一的安全密钥(用于您使用的用户名)与密码连接起来.例如(Python 中的示例),您的请求应该是:

If you are using Username and Password OAuth authentication, please make sure you have concatenated the unique security key (for the username that you are using) with the password. For instance (example in Python), your request should be:

import requests
import json

params = {
    "grant_type": "password",
    "client_id": "client_id", # Consumer Key
    "client_secret": "client_secret", # Consumer Secret
    "username": "username", # The email you use to login
    "password": "password + unique_security_key"}

headers = {'content_type':'application/x-www-form-urlencoded'}

r = requests.post("https://login.salesforce.com/services/oauth2/token", params=params, headers=headers)
access_token = r.json().get("access_token")
instance_url = r.json().get("instance_url")
print("Access Token:", access_token)
print("Instance URL", instance_url)

获取安全密钥:

  • 登录您的 Salesforce 帐户
  • 点击右上角的用户名.
  • 在左侧窗格中,点击个人 > 重置我的安全令牌

唯一的安全令牌将发送到您的电子邮件.请将密钥与您的密码连接起来.

A Unique security token will be sent to your email. Please concatenate the key with your password.

如果您仍然遇到错误,请检查以下步骤:

If you still experiencing the error, please check the following steps:

导航应用程序 > 管理连接的应用程序 > 您连接的应用程序 > 编辑 > OAuth 策略 > 允许允许的用户对所有用户进行自我授权

Navigate Apps > Manage Connected Apps > Your Connected App > Edit > OAuth Policies > Enable Permitted users to All users may self-authorize

管理应用 > 连接的应用 > 您连接的应用 > 启用 IP 放宽以放宽 IP 限制.

Manage Apps > Connected Apps > Your Connected App > Enable IP Relaxation to Relax IP restrictions.

希望这会有所帮助.

这篇关于Salesforce OAuth 身份验证不适用于用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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