OAuth のフロー変数

Apigee Edge は、OAuth 1.0a と OAuth 2 の機能を一連のポリシーにカプセル化しています。作成、検証、保管など、トークンや秘密情報のライフサイクル管理は、バックエンド サービスに代わって Apigee Edge が行います。

このドキュメントでは、OAuth ポリシーが定義するフロー変数の仕様を示します。この変数は、OAuth フローのカスタム動作を実装するために使用できます。OAuth の使用方法については、OAuth をご覧ください。

OAuth 2.0 のフロー変数

この表で定義されたフロー変数は、それぞれの OAuth ポリシーが実行されるときに設定されます。したがって、API プロキシフロー実行されている他のポリシーまたはアプリケーションで使用できます。

アクセス トークンのポリシーを検証する
  • organization_name
  • organization_name
  • developer.id
  • developer.app.name
  • client_id
  • grant_type
  • token_type
  • access_token
  • accesstoken.{custom_attribute}
  • issued_at
  • expires_in
  • status
  • scope
  • apiproduct.name*
  • apiproduct.<custom_attribute_name>*

* API プロダクト変数

サンプル ポリシー:


<OAuthV2 name="VerifyAccessToken">
    <Operation>VerifyAccessToken</Operation>
    <Scope>space-separated-scopes</Scope>*
    <AccessToken>flow.variable</AccessToken>*
    <AccessTokenPrefix>Bearer</AccessTokenPrefix>*
</OAuthV2>

ベアラー トークンのみサポートします。MAC トークンはサポートしません。

デフォルトでは、アクセス トークンは Authorization HTTP リクエスト ヘッダーに渡す必要があります。

例:

"Authorization: Bearer {PlainText_AccessToken}"

どの flow.variable も次のように渡せます。

  • HTTP Header: request.header.{variable_name}
  • Query parameter: request.queryparam.{variable_name}
  • Form parameter: request.formparam.{variable_name}

オプションのフィールドが指定されていない場合は、OAuth 2.0 の仕様に従って値が抽出されます。

認証コードのポリシーの生成
成功時には以下の変数が設定されます。
  • oauthv2authcode.{policy_name}.code
  • oauthv2authcode.{policy_name}.redirect_uri
  • oauthv2authcode.{policy_name}.scope
  • oauthv2authcode.{policy_name}.client_id

サンプル ポリシー:


<OAuthV2 name="GetAuthCode">
  <Operation>GenerateAuthorizationCode</Operation>
  <ExpiresIn>1000<ExpiresIn>
  <ResponseType>flow.variable</ResponseType>*
  <ClientId>flow.variable</ClientId>*
  <RedirectUri>flow.variable</RedirectUri>*
  <Scope>flow.variable</Scope>*
  <State>flow.variable</State>*
  <Attributes>*
    <Attribute name=”1” ref=”flow.variable”>value1</Attribute>
    <Attribute name=”2” ref=”flow.variable”>value2</Attribute>
  </Attributes>
</OAuthV2>

* 省略可

どの flow.variable も次のように渡せます。

  • HTTP Header: request.header.{variable_name}
  • Query parameter: request.queryparam.{variable_name}
  • Form parameter: request.formparam.{variable_name}

オプションのフィールドが指定されていない場合は、OAuth 2.0 の仕様に従って値が抽出されます。

属性値は、指定されたフロー変数から動的に取得されるか、ポリシーのデフォルト値を使用して静的に取得されます。

両方を指定すると、フロー変数が優先されます。

認証コード、ユーザー認証情報、クライアント認証情報の許可タイプに対するアクセス トークン ポリシーの生成
成功時には以下の変数が設定されます。
  • oauthv2accesstoken.{policy_name}.access_token
  • oauthv2accesstoken.{policy_name}.token_type
  • oauthv2accesstoken.{policy_name}.expires_in
  • oauthv2accesstoken.{policy_name}.refresh_token

サンプル ポリシー:


<OAuthV2 name="GenerateAccessToken">
  <Operation>GenerateAccessToken</Operation>
  <ExpiresIn>1000<ExpiresIn>
  <SupportedGrantTypes>*
    <GrantType>authorization_code</GrantType>
    <GrantType>password</GrantType>
   <GrantType>client_credentials</GrantType>
  </SupportedGrantTypes>
  <GrantType>flow.variable</GrantType>*
  <ClientId>flow.variable</ClientId>*
  <RedirectUri>flow.variable</RedirectUri>*
  <Scope>flow.variable</Scope>*
  <AppEndUser>flow.variable</AppEndUser>*
  <Code>flow.variable</Code>*
  <UserName>flow.variable</UserName>*
  <PassWord>flow.variable</PassWord>*
  <Attributes>*
    <Attribute name=”1” ref=”flow.variable”>value1</Attribute>
    <Attribute name=”2” ref=”flow.variable”>value2</Attribute>
  </Attributes>
</OAuthV2>

* 省略可

どの flow.variable も次のように渡せます。

  • HTTP Header: request.header.{variable_name}
  • Query parameter: request.queryparam.{variable_name}
  • Form parameter: request.formparam.{variable_name}

オプションのフィールドが指定されていない場合は、OAuth 2.0 の仕様に従って値が抽出されます。

属性値は、指定されたフロー変数から動的に取得されるか、ポリシーのデフォルト値を使用して静的に取得されます。

両方を指定すると、フロー変数が優先されます。

Implicit 許可タイプに対するアクセス トークンの生成
成功時には以下の変数が設定されます。
  • oauthv2accesstoken.{policy_name}.access_token
  • oauthv2accesstoken.{policy_name}.token_type
  • oauthv2accesstoken.{policy_name}.expires_in
  • oauthv2accesstoken.{policy_name}.refresh_token

サンプル ポリシー:


<OAuthV2 name="GenerateAccessToken">
  <Operation>GenerateAccessTokenImplicitGrant</Operation>
  <ExpiresIn>1000<ExpiresIn>
  <ResponseType>flow.variable></ResponseType>*
  <ClientId>flow.variable></ClientId>*
  <RedirectUri>flow.variable></RedirectUri>*
  <Scope>flow.variable></Scope>*
  <State>flow.variable></State>*
  <AppEndUser>flow.variable</AppEndUser>*
  <Attributes>*
    <Attribute name=”1” ref=”flow.variable”>value1</Attribute>
    <Attribute name=”2” ref=”flow.variable”>value2</Attribute>
  </Attributes>
</OAuthV2>

* 省略可

どの flow.variable も次のように渡せます。

  • HTTP Header: request.header.{variable_name}
  • Query parameter: request.queryparam.{variable_name}
  • Form parameter: request.formparam.{variable_name}

オプションのフィールドが指定されていない場合は、OAuth 2.0 の仕様に従って値が抽出されます。

属性値は、指定されたフロー変数から動的に取得されるか、ポリシーのデフォルト値を使用して静的に取得されます。

両方を指定すると、フロー変数が優先されます。

アクセス トークンのポリシーを更新する
成功時には以下の変数が設定されます。
  • oauthv2accesstoken.{policy_name}.access_token
  • oauthv2accesstoken.{policy_name}.token_type
  • oauthv2accesstoken.{policy_name}.expires_in
  • oauthv2accesstoken.{policy_name}.refresh_token

サンプル ポリシー:


<OAuthV2 name="RefreshAccessToken">
  <Operation>RefreshAccessToken</Operation>
  <ExpiresIn>1000<ExpiresIn>
  <GrantType>flow.variable</GrantType>*
  <RefreshToken>flow.variable</RefreshToken>*
</OAuthV2>

* 省略可

どの flow.variable も次のように渡せます。

  • HTTP Header: request.header.{variable_name}
  • Query parameter: request.queryparam.{variable_name}
  • Form parameter: request.formparam.{variable_name}

オプションのフィールドが指定されていない場合は、OAuth 2.0 の仕様に従って値が抽出されます。

クライアント属性のポリシーを取得する

サンプル ポリシー:


<GetOAuthV2Info name="GetClientAttributes">
<ClientId ref="{variable_name}"/>
</GetOAuthV2Info>

サンプル ポリシー:


<GetOAuthV2Info name="GetClientAttributes">
  <ClientId>{client_id}</ClientId>
</GetOAuthV2Info>
アクセス トークン属性値のポリシーを取得する
成功時には以下の変数が設定されます。
  • oauthv2accesstoken.{policy_name}.access_token
  • oauthv2accesstoken.{policy_name}.scope
  • oauthv2accesstoken.{policy_name}.refresh_token
  • oauthv2accesstoken.{policy_name}.accesstoken.{custom_attribute_name}
  • oauthv2accesstoken.{policy_name}.developer.id
  • oauthv2accesstoken.{policy_name}.developer.app.name
  • oauthv2accesstoken.{policy_name}.expires_in
  • oauthv2accesstoken.{policy_name}.status

サンプル ポリシー:


<GetOAuthV2Info name="GetTokenAttributes">
  <AccessToken ref="{variable_name}"/>
</GetOAuthV2Info>

サンプル ポリシー:


<GetOAuthV2Info name="GetTokenAttributes">
<AccessToken>{access_token}</AccessToken>
</GetOAuthV2Info>
認可コード属性のポリシーを取得する

サンプル ポリシー:


<GetOAuthV2Info name="GetAuthCodeAttributes">
 <AuthorizationCode ref="{variable_name}"/>
</GetOAuthV2Info>

サンプル ポリシー:


<GetOAuthV2Info name="GetAuthCodeAttributes">
    <AuthorizationCode>{authorization_code}</AuthorizationCode>
</GetOAuthV2Info>
リフレッシュ トークン属性のポリシーを更新する

サンプル ポリシー:


<GetOAuthV2Info name="GetTokenAttributes">
  <RefreshToken ref="{variable_name}"/>
</GetOAuthV2Info>

サンプル ポリシー:


<GetOAuthV2Info name="GetTokenAttributes">
    <RefreshToken>{refresh_token}</RefreshToken>
</GetOAuthV2Info>

OAuth 1.0a フロー変数

この表で定義されたフロー変数は、それぞれの OAuth ポリシーが実行されるときに設定されます。したがって、API プロキシフロー実行されている他のポリシーまたはアプリケーションで使用できます。

リクエスト トークンのポリシーを生成する

サンプル ポリシー:

<OAuthV1 name="GenerateRequestToken">
  <Operation>GenerateRequestToken</Operation>
</OAuthV1>

成功時には以下の変数が設定されます。

  • oauth_token
  • oauth_token_secret
  • oauth_callback_confirmed
  • oauth_response
  • oauth_consumer_key
  • oauth_consumer_secret

アクセス トークンのポリシーを生成する

サンプル ポリシー:

<OAuthV1 name="GenerateAccessToken">
  <Operation>GenerateAccessToken</Operation>
</OAuthV1>

成功時には以下の変数が設定されます。

  • oauth_token
  • oauth_token_secret
  • oauth_response
  • oauth_consumer_key
  • oauth_consumer_secret

アクセス トークン検証ポリシー

サンプル ポリシー:

<OAuthV1 name="VerifyAccessToken">
  <Operation>VerifyAccessToken</Operation>
</OAuthV1>

成功時には以下の変数が設定されます。

  • oauth_token
  • oauth_token_secret
  • oauth_response
  • oauth_consumer_key
  • oauth_consumer_secret

API キー ポリシーを検証する

サンプル ポリシー:

<GetOAuthV1Info name="VerifyApiKey">
  <OAuthConfig>{config_name}</OAuthConfig>*
  <APIKey ref="{variable_name}" />
</GetOAuthV1Info>

* 省略可

成功時には以下の変数が設定されます。

  • oauth_consumer_key
  • oauth_consumer_secret

コンシューマ ポリシーを検証する

サンプル ポリシー:

<GetOAuthV1Info name="VerifyConsumer">
  <OAuthConfig>{config_name}</OAuthConfig>*
  <ConsumerKey ref="{variable_name}" />
</GetOAuthV1Info>

* 省略可

成功時には以下の変数が設定されます。

  • oauth_consumer_key
  • oauth_consumer_secret

トークン ポリシーを検証する

サンプル ポリシー:

<GetOAuthV1Info name="VerifyToken">
  <OAuthConfig>{config_name}</OAuthConfig>*
  <RequestToken ref="{variable_name}" />
</GetOAuthV1Info>

* 省略可

成功時には以下の変数が設定されます。

  • oauth_token
  • oauth_token_secret