OAuth2.0 クライアントログイン情報フローを実行するための外部クライアントアプリケーション作成手順と、cURLコマンドを使用したトークン取得手順を解説します。なお、後述の手順は一般的な動作確認を行うための設定例です。ご利用の外部システムやアプリケーションの要件に応じて、外部クライアントアプリケーションの詳細なオプションや、リクエスト時の情報などは調整してください。
以下に設定および実行手順の例をご紹介します。
1. [設定] から [外部クライアントアプリケーションマネージャー] へ遷移します。
2. [新規外部クライアントアプリケーション] をクリックします。
3. 以下の設定を実施して、[作成] をクリックします。
4. 作成した外部クライアントアプリケーションの設定ページで、[設定] タブ内の "OAuth" セクションを開きます。
5. [コンシューマー鍵と秘密] をクリックします。
6. [ID を検証] のプロセスを完了させます。
7. 表示される「コンシューマー鍵 (client_id)」と「コンシューマーの秘密 (client_secret)」を控えます。
注意: cURL コマンドは URL を用いて HTTP/HTTPS などのプロトコルでデータ送信を行うオープンソースのソフトウェアです。弊社 Salesforce 提供のツールではございません。ご利用の際には外部サイトを適宜ご参照ください。
1. 以下の形式の URL でブラウザーへアクセスします。
| https://{myDomain}/services/oauth2/authorize?response_type=code&client_id={client_id}&redirect_uri=https://login.salesforce.com/services/oauth2/callback |
2. ユーザー認証を完了させます。
3. 遷移したページの URL の code パラメーターの値を控えます。
| https://login.salesforce.com/services/oauth2/callback?code=XXXXX |
注意 : code に含まれる %3D の値は = の文字が URL エンコードにより変換されています。控えた code の %3D は = に変更してください。
1. 以下の形式で cURL コマンドを実行します。
| curl -X POST "{myDomain}/services/oauth2/token" -d "grant_type=authorization_code&client_id={client_id}&client_secret={client_secret}&redirect_uri=https://login.salesforce.com/services/oauth2/callback" --data-urlencode "code={code}" |
2. コマンドラインで access_token や refresh_token が返却されていることを確認します。
| {"access_token":"AAAAA","refresh_token":"BBBBB","signature":"CCCCC","scope":"refresh_token api","instance_url":"DDDDD","id":"EEEEE","token_type":"Bearer","issued_at":"FFFFF"} |
C. 更新トークンフローによるアクセストークンの再取得1. 以下の形式で cURL コマンドを実行します。
| curl -X POST "{myDomain}/services/oauth2/token" -d "grant_type=refresh_token&client_id={client_id}&client_secret={client_secret}&refresh_token={refresh_token}" |
2. コマンドラインで再取得した access_token が返却されることを確認します。
| {"access_token":"AAAAA","signature":"BBBBB","scope":"refresh_token api","instance_url":"CCCCC","id":"DDDDD","token_type":"Bearer","issued_at":"EEEEE"} |
以上の手順で OAuth2.0 Web サーバーフロー、および更新トークンフローによるアクセストークンの取得動作を確認できます。
Web サーバーフローで PKCE を用いた認証を求める場合、以下の外部クライアントアプリケーションの PKCE の設定をオンにします。
その上で、Web サーバーフローによりアクセストークンを取得するには後述の順序でリクエストを行います。
| サポートされる認証フローに Proof Key for Code Exchange (PKCE) 拡張を要求 |
1. 以下の形式で cURL コマンドを実行します。
| curl -X GET "{myDomain}/services/oauth2/pkce/generator" |
2. コマンドラインで code_challenge や code_verifier が返却されていることを確認します。
| {"code_challenge_method":"S256","code_challenge":"XXXXX","code_verifier":"YYYYY"} |
B. 認証コードの要求1. 以下の形式の URL でブラウザーへアクセスします。
| https://{myDomain}/services/oauth2/authorize?response_type=code&client_id={client_id}&redirect_uri=https://login.salesforce.com/services/oauth2/callback&code_challenge={code_challenge} |
2. ユーザー認証を完了させます。
3. 遷移したページの URL の code パラメーターの値を控えます。
1. 以下の形式で cURL コマンドを実行します。
| curl -X POST "{myDomain}/services/oauth2/token" -d "grant_type=authorization_code&client_id={client_id}&client_secret={client_secret}&redirect_uri=https://login.salesforce.com/services/oauth2/callback&code_verifier={code_verifier}" --data-urlencode "code={code}" |
2. コマンドラインで access_token や refresh_token が返却されていることを確認します。
以上の手順で PKCE を用いた Web サーバーフローの動作を確認できます。
コンシューマー鍵、コンシューマーの秘密、アクセストークン、リフレッシュトークンは機密情報です。実装・運用時には外部への漏洩を防ぐため、適切なセキュリティ対策を講じて管理してください。
本記事においては、ブラウザおよび cURL コマンドにより動作確認の手順をご紹介しましたが、実際には外部システムより各要求が行われます。例に記載した方法以外にも多くのパラメーターがあることからも、API 実行元のシステムや業務上の要件に応じた設定を行う必要があります。そのため、必要に応じてシステム開発者様やアプリ提供元企業まで外部クライアントアプリケーションの設定方法をご相談ください。
Web アプリケーションインテグレーションの OAuth 2.0 Web サーバーフロー
Proof Key for Code Exchange (PKCE) 拡張
Retirement of OAuth 2.0 Username-Password Flow for Connected Apps (Release Update)
005318017

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.