ServiceNow インスタンスを OAuth クライアントとして設定する方法Summary<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } この記事では、権限許可タイプ「リソース所有者のパスワード認証情報」を使用して ServiceNow インスタンスを OAuth クライアントとして設定し、アクセストークンとリフレッシュトークンの両方を提供してインスタンスにアクセスできるようにする方法について説明します。 Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } すべてのリリース。 Instructions<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } OAuth クライアントとしての ServiceNow インスタンスの設定 アプリケーションレジストリ (システム OAuth > アプリケーションレジストリ) に移動します。「New」をクリックし、「Create an OAuth API endpoint for external clients」を選択します。要件に従ってフォームに記入し、「送信」をクリックします。不明な場合は、[名前] フィールドに入力するだけで十分です。注:「クライアント ID」と「クライアントシークレット」は後で使用するため、書き留めておいてください。 Postman を使用したアクセストークンとリフレッシュトークンの取得 Postman を開き、新しい要求を作成します。REST メソッドを「POST」に、要求 URL を「https://<instance_name>.service-now.com/oauth_token.do」に設定します。「本文」タブを選択し、「x-www-form-url-encoded」にチェックを入れます。確認に従って、キー:値ペアを入力します。これは本文セクションでのみ行う必要があります。 grant_type: passwordclient_id: <前のセクションからの client_id>client_secret: <前のセクションからの client_secret>ユーザー名: <インスタンスで認証するためのユーザー名>password : <インスタンスで認証するためのパスワード> 「送信」をクリックすると、アクセストークンとリフレッシュトークンの両方を含む次のような応答が届きます。 {"access_token": "CH1XAvt8FU1yjsRHq-ixDB1Fct4mpcztmvlD_2Wfu_F83thGqcPVfjvHsf8HvBi_ByeMsPXz1Igd5OYdADfXFw","refresh_token": "EuoV22-H28J_frduuMUlKXcuJ-tFz9F2Pe_PSNa3Ml3H8bzG4FIn8ChCcmtLJkMeP_T4a-MBI-c6YRW_1D4Mcw","scope": "useraccount","token_type": "Bearer","expires_in": 1799} アクセストークンを使用して ServiceNow インスタンスのリソースにアクセスする。 Postman を開き、新しい要求を作成します。REST メソッドを「GET」に設定し、要求 URL をリソースエンドポイントに設定します。例 https://<instance_name>.service-now.com/api/now/table/incident?sysparm_limit=1「Auth」タブをクリックし、「Type」を「No Auth」に設定します。[ヘッダー] タブをクリックし、アクセストークンを使用して以下の KEY:VALUE ペアを構成します。 Authorization : Bearer <前のセクションの access_token> [送信] をクリックすると、リソースの応答ペイロードが受信されます。 リフレッシュトークンを使用してアクセストークンを更新する。 Postman を開き、新しい要求を作成します。REST メソッドを「POST」に、要求 URL を「https://<instance_name>.service-now.com/oauth_token.do」に設定します。「本文」タブを選択し、「x-www-form-url-encoded」にチェックを入れます。確認に従って、キー:値ペアを入力します。 grant_type: refresh_tokenclient_id: <前のセクションからの client_id>client_secret: <前のセクションからの client_secret>refresh_token: <前のセクションからの refresh_token> 「送信」をクリックすると、新しいアクセストークンを含む次のような応答が届きます。 {"access_token": "Y5KagMC8REDaILJL5Ohvg1SauPn36iCC2kV8-miwVEjy7j6AjJtY9lcsA5gvOC7EtFDBGd9Zw7PB-2XA4rs0XA","refresh_token": "EuoV22-H28J_frduuMUlKXcuJ-tFz9F2Pe_PSNa3Ml3H8bzG4FIn8ChCcmtLJkMeP_T4a-MBI-c6YRW_1D4Mcw","scope": "useraccount","token_type": "Bearer","expires_in": 1799}