问题
如何使用 Zendesk v2 API 对 API 请求进行身份验证?
回答
您必须是已验证用户才能发出通过身份验证的 API 请求。要对 API 请求进行身份验证,请使用电邮地址和密码、电邮地址和 API 密钥,或 OAuth 访问密钥进行基本身份验证。
不同身份验证方法对授权标头的设置各不相同。不处理在有效负载或 URL 中发送的凭证。每个选项如下所示:
密码身份验证
如果您使用基本身份验证,请结合您的电邮地址和密码以生成授权标头。要使用基本身份验证,请在管理中心的应用和整合 > API> Zendesk API 下以及相关身份验证部分(团队成员或终端用户)启用密码访问。
将电邮地址和密码组合的格式设置为 Base-64
编码字符串。有关如何设置授权标头格式的示例,请查看以下代码块。
Authorization: Basic {base-64-encoded email_address:password}
API 密钥身份验证
如果您使用 API 密钥,请结合您的电邮地址和 API 密钥以生成授权标头。将电邮地址和 API 密钥组合的格式设置为 Base-64
编码字符串。有关如何设置授权标头格式的示例,请查看以下代码块。
Authorization: Basic {base-64-encoded email_address/token:api_token}
OAuth 访问密钥身份验证
如果您使用 OAuth 进行身份验证,请这样设置授权标头的格式:
Authorization: Bearer oauth_access_token
有关更多信息,请参阅文章:对您的应用程序使用 OAuth 身份验证。
查看您的授权标头
要查看您的应用发送的确切内容,请使用第三方页面,例如 Request Bin。将您的标头与 Webhook 使用 OAuth 身份验证生成的标头进行比较。将 Webhook 指向您的 requestb.in URL,然后在添加 Webhook 页面上,单击测试 Webhook 以查看实际情况:
当请求到达您的 requestb.in 后,显示如下:
Authorization: Bearer
之后的字符串是由 RequestBin 在账户设置中的 Programmatic Access(程序访问)下提供的 API 密钥。
如果您使用 Python 提出请求,请按照如下方式设置会话标头。
session = requests.Session()
session.headers = {'Content-Type': 'application/json', 'Authorization': 'Basic Basic_64_encoded_code'}
有关更多信息,请参阅开发者文档:Security and authentication(英文)。
20 条评论
Glenn Chen
Hi Paolo,
First, I need to emphasize that “I don't want to ask users about their passwords”.
I want to show some Zendesk content in my web app based on users' authorization status.
If I go with Oauth2, I will need to ask user's password, this is the example from Oauth2 Password grant type
If I go with Making API requests on behalf of end users, I also need password from the user.
Either way I need users' passwords to do it, is there a way I can do it without requesting their passwords?
0
Paolo
If you need the actual user's password, unfortunately, there is no way on getting this unless you ask them. In addition, it is not recommended to have your end user's password as this may arise security concerns. Can you please explain further the purpose of why the actual user password is needed, and the an OAuth or a token is not sufficient?
Best,
Paolo | Technical Support Engineer | Zendesk
0
Glenn Chen
Hi all
I have similar concern with Ramy Ben Aroya' s comment here
I want to show some Zendesk content in my web app. As far as I know, I can do it either through Oauth2 or by making a request on behalf of an user, but eventually I will need end users' passwords, is there a way I can do it without having to request their passwords?
0
Benedikt Hild
Hi All,
I ran into the same issues described by some people. Here's my working solution:
I enconded the credentials mentioned on the dokumention '{email_address}/token:{api_token}'
with UTF-8.
$Base64AuthInfo = "{email_address}/token:{api_token}"
$Base64AuthInfo = [convert]::ToBase64String([text.encoding]::UTF8.GetBytes($Base64AuthInfo))
My previous attempt encoding with unicode did not work.
$Base64AuthInfo = "{email_address}/token:{api_token}"
$Base64AuthInfo = [convert]::ToBase64String([text.encoding]::Unicode.GetBytes($Base64AuthInfo))
Maybe a mention of that could be usefull inside the API documentation.
Cheers!!
Benedikt
2
Dermot Doran Cato Networks
Hi All!
If you are working on macOS, I recommend that you follow the tip given by Nick Bolton. I tried to create the base64 code using the -i option of the base64 comman, but it kept adding an extra character to the end of encoded output.
Cheers!!
Dermot
0
Dane
Yes, you can use SSO for your end users. Please refer to Providing multiple sign-in options for team members and end users.
-1
Felipe Costa
Hello, SSO authentication works to customer's side?
We don't have our customer's zendesk password.
0
Fraser, Vanessa
I'm sure it is something I'm doing wrong but I have been over and over that article and am not seeing what I have done wrong. I'll contact support. Also I can curl using the email/token:tokeninfo so it has to do with my encoding of the email/token:tokeninfo.
0
Dwight Bussman
Hi Vanessa Fraser
After doing that encoding are you passing the encoded value in as a Basic Authorization header as documented here: https://developer.zendesk.com/api-reference/introduction/security-and-auth/#basic-authentication
If that doesn't help sort things out for you, I recommend contacting our support team to look into logs for your specific account.
0
Fraser, Vanessa
Hi! I'm trying to use Azure Logic Apps to Authentic for a POC but I keep getting 401 Couldn't authenticate you.
I've encoded my username/token:aaaa via powershell this way but I must be missing something.
$text = "myname@mydomain.com/token:tokentexthere"
$encoded = [convert]::ToBase64String([text.encoding]::Unicode.GetBytes($text))
$encoded
I went through this article and tried OAuth, api, user/password but just not getting authenticated.
Any ideas would be welcome!
0
登录再写评论。