質問
Zendesk v2 APIを使用してAPIリクエストを認証するにはどうすればよいですか?
回答
認証済みAPIリクエストを実行するには、認証済みのZendeskユーザーであることが必要です。APIリクエストを認証するには、メールアドレスとパスワード、メールアドレスとAPIトークン、またはOAuthアクセストークンでBasic認証を使用します。
それぞれの認証方法で、承認ヘッダーの設定が異なります。ペイロードまたはURLで送信された資格情報は処理されません。各オプションを以下に示します。
パスワード認証
Basic認証を使用している場合は、メールアドレスとパスワードを組み合わせて承認ヘッダーを生成できます。Basic認証を使用するには、管理センターの「アプリおよびインテグレーション」>「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などのサードパーティページを使用します。OAuth認証を使用するWebhookにより生成されるヘッダーと、自分のヘッダーを比較します。Webhookをrequestb.inのURLにポイントし、「Webhookを追加」ページで、「Webhookをテスト」をクリックして、実際の動作を確認します。
リクエストがrequestb.inに届くと、次のように表示されます。
Authorization: Bearer
の後ろの文字列は、「プログラムによるアクセス」にあるアカウント設定でRequestBinで提供されるAPIキーです。
Pythonを使用してリクエストを実行する場合、セッションヘッダーを以下のように設定します。
session = requests.Session()
session.headers = {'Content-Type': 'application/json', 'Authorization': 'Basic Basic_64_encoded_code'}
詳細については、開発ドキュメントを参照してください:「セキュリティおよび認証」
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 5410209777818
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
サインインしてコメントを残してください。