ServiceNow Rest API OAuth 返回“未授权”错误



我设法使用用户名和密码使用基本身份验证访问 Rest API。现在我正在尝试使用 OAuth 访问 Rest API。我指的是这篇文章

这是我创建的 POST 消息的格式(使用 Chrome 的 Postman),

POST /oauth_token.do HTTP/1.1
Host: devxxxxx.service-now.com
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46Q0BycjBsMTIz
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

网址编码正文:

grant_type=password&client_id=xxxxxx&client_secret=xxxxxx&username=admin&username=xxxxxx

我尝试了编码的身体和没有编码的身体,它给出了相同的结果。

响应

{
    "error": "server_error",
    "error_description": "access_denied"
}

我在这里错过了什么吗?"管理员"用户是否具有执行此操作和获取令牌的权限?

好的,两件事,

  1. 错误(在正文中键入用户名两次而不是密码)

grant_type=密码&client_id=xxxxxxx&client_secret=xxxxxxx&用户名=admin&用户名=xxxxxxx

应该是,

grant_type=密码&client_id=xxxxxxx&client_secret=xxxxxxx&用户名=admin&password=xxxxxxx

  1. 对于此请求,不应具有授权标头。我删除了基本授权标头。它现在正在工作。

回顾

使用邮递员,

确保端点为"https://[instance-now].com/oauth_token.do"

头:接受:应用程序/json

Body (x-www-form-urlencoded)

grant_type:密码client_id: xxxxxxclient_secret: xxxxxxx用户名: username_01密码:password_01

希望这会帮助某人....

最新更新