機械翻訳について

OAuthクライアント資格証明

OAuth-client-credentials権限で保護されたREST APIの呼出しをサポートするには、OAUTH_CLIENT_CREDENTIALS管理対象セキュリティ・ポリシーを使用します。 接続定義に必要なセキュリティ・ポリシーをカスタマイズできます。

概要

クライアント・アプリケーションは、リソース所有者の介入を使用せずに、サード・パーティ・アプリケーションのリソースにアクセスします。

このポリシーのデフォルト実装はRFC 6749です。 ただし、実装はRFCが示す方法とは異なる場合があります。 したがって、RFC 6749準拠ポリシーを拡張して、1つ以上のステップをオーバーライドします。

OAuthクライアント資格証明ポリシーをドキュメントに追加するには、使用可能な認証スキーム・テンプレートを使用します。 「新規接続定義の実装」を参照してください。

セキュリティ・プロパティ

このセキュリティ・ポリシーを使用する接続定義は、securityPropertiesセクションで次のプロパティを定義します。 「接続プロパティおよびサンプル・コード」を参照してください。

name, displayName, shortDescription列およびdescription列の値は、アダプタ定義ドキュメントにセキュリティ・ポリシーを挿入したときに表示されるデフォルト値を示します。 これらの値は、必要に応じて更新できます。

name displayName shortDescription description データ型 必須

oauth.client.id

Client Id

for example: 123-xxx.apps.googleusercontent.com

Used to identify the client(the software requesting an access token) that is making the request.

The value passed in this parameter must exactly match the value shown in your API console project.

String

はい

oauth.client.secret

Client Secret

<unique random string matches your API console project>

Used to authorize the client(the software requesting an access token) that is making the request.

The value passed in this parameter must exactly match the value shown in your API console project.

パスワード

はい

oauth.access.token.uri

Access Token URI

for example: https://accounts.google.com/o/oauth2/token

A request should be sent to this URI for obtaining an access token.

String

はい

oauth.scope

Scope

for example: read,write.

Permissions your application is requesting on behalf of the user.

String

いいえ

セキュリティ・ポリシーの拡張

必要に応じて、セキュリティ・ポリシーを拡張します。

セキュリティ・ポリシーは、HTTPリクエストの構造を定義します。 このセキュリティ・ポリシーのデフォルトの実装はRFC 6749です。 ただし、実装はRFCが示す方法とは異なる場合があります。 アダプタを作成するアプリケーションが標準セキュリティ・ポリシーをサポートしているが、追加情報が必要な場合は、RFC 6749準拠ポリシーを拡張して、1つ以上のステップをオーバーライドできます。 セキュリティ・ポリシーを拡張する場合は、リクエストの構造を変更します。

  1. OAuthプロバイダのドキュメントを読み、次の情報を収集します。
    収集する情報 説明

    AccessTokenRequest

    認可サーバーでは、AccessTokenRequestが必要です。 必要な情報、および情報を承認サーバーに送信するメソッドを決定します。

    次の例は、RFC 6749に従ってトークン・リクエストにアクセスするためのサンプル・コードです:

    {
        "method": "POST",
        "uri": "${.securityProperties.oauth.access.token.uri}",
        "params": {
            "template": {},
            "query": {
                "client_id": "${.securityProperties.oauth.client.id}",
                "redirect_uri": "${redirect_uri}",
                "client_secret": "${.securityProperties.oauth.client.secret}",
                "grant_type": "authorization_code"
            }
        },
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded",
            "Authorization" : "Basic " + ((.securityProperties.oauth.client.id)+\":\"+(.securityProperties.oauth.client.secret") | @base64)
    
        },
        "body": "grant_type=client_credentials&scope=${.securityProperties.oauth.scope}"
    }

    AccessTokenRequestのレスポンス

    認可サーバーがアクセス・トークン・リクエストへのレスポンスを返す方法、およびレスポンスで返される情報を確認します。 レスポンスのタイプはプロバイダごとに異なります。 ほとんどのプロバイダは、次の例に示すように、アクセス・トークン・レスポンスを返します:

    {
      "token_type": "Bearer",
      "access_token": "the access token value"
    }

    APIのコール時に、アプリケーションがアクセス・トークンがリクエストとともに送信されることを想定するメソッド

    多くのアプリケーションでは、アクセス・トークン以外の追加情報を求めています。 たとえば、次の例に示すように、ほとんどのアプリケーションでは、有効なアクセス・トークンがヘッダーとして送信されることを想定しています。

    次のコード・スニペットは、RFC 6749に従ったアクセス・トークンの使用方法を示しています:

    -H "Authorization: Bearer [access_token]"
  2. OAuthフローの1つ以上のステップを変更して、必要に応じて管理対象セキュリティ・ポリシーを拡張します。

サンプル・コード: OAuthクライアントの資格証明

次のサンプル・コードは、クライアント資格証明セキュリティ・ポリシーの実装を示しています。

"securityPolicies": [
         {
             "type": "managed",
             "policy": "OAUTH_CLIENT_CREDENTIALS",
             "description": "OAUTH2 CLIENT CREDENTIALS Policy",
             "displayName": "OAUTH2 CLIENT CREDENTIALS Policy",
             "scope": "ACTION",
             "securityProperties": [
                 {
                     "name": "oauth.client.id",
                     "displayName": "Client Id",
                     "description": "Client Id",
                     "shortDescription": "Client Id",
                     "required": true,
                     "hidden": false
                 }, {
                     "name": "oauth.client.secret",
                     "displayName": "Client Secret",
                     "description": "Client Secret",
                     "shortDescription": "Client Secret",
                     "required": true,
                     "hidden": false
                 }, {
                     "name": "oauth.access.token.uri",
                     "default": "https://login.abcxyz.com/01131-a123-4321-a999-347dh4/oauth2/token",
                     "required": false,
                     "hidden": true
                 }, {
                     "name": "oauth.scope",
                     "default": "",
                     "required": false,
                     "hidden": true
                 }, {
                     "name": "oauth.request.content.type",
                     "default": "application/x-www-form-urlencoded",
                     "required": false,
                     "hidden": true
                 }, {
                     "name": "clientAuthentication",
                     "default": "client_credentials_as_header",
                     "required": false,
                     "hidden": true
                 }
             ]                 
         }
     ],
     "test": "flow:TestConnectionFlow"
 }

サンプル・コード: OAuthクライアント資格証明、拡張

次のコード・サンプルは、拡張コード認可ポリシーを示しています。

"securityPolicies": [
      {
        "type": "managed",
        "policy": "OAUTH_CLIENT_CREDENTIALS",
        "description": "OAuth Client Credentials Policy",
        "displayName": "OAuth Client Credentials Policy",
        "scope": "ACTION",
        "securityProperties": [
          {
            "name": "oauth.client.id",
            "displayName": "Client Id",
            "description": "Client Id",
            "shortDescription": "Client Id",
            "required": true,
            "hidden": false
          },
          {
            "name": "oauth.client.secret",
            "displayName": "Client Secret",
            "description": "Client Secret",
            "shortDescription": "Client Secret",
            "required": true,
            "hidden": false
          },
          {
            "name": "oauth.access.token.uri",
            "default": "https://accounts.abacxyz.com/o/oauth2/token",
            "required": false,
            "hidden": true
          },
          {
            "name": "oauth.scope",
            "default": "https://www.abcxyz.com/auth/videos",
            "required": false,
            "hidden": true
          },
          {
            "name": "clientAuthentication",
            "default": "client_credentials_in_header",
            "required": false,
            "hidden": true
          }
        ],
        "authExtension": {
          "accessTokenRequest": {
            "method": "POST",
            "uri": "https://www.googleapis.com/oauth2/v4/token",
            "params": {
              "template": {
              },
              "query": {
                "client_id": "[your_client_id]",
                "client_secret": "[your_client_secret]",
                "grant_type": "client_credentials"
              }
            },
            "headers": {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            "body": "false"
          },
          "fetchRules": {
            "access_token": "access.[tT]oken",
            "expiry": "expires.*",
            "token_type": "token.?[tT]ype"
          },
          "accessTokenUsage": {
            "headers": {
              "Authorization": "Bearer : ${access_token}"
            }
          }
        }
      }
    ],
    "test": "flow:testConnectionFlow"
  }