OAuth 流程變數

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

Apigee Edge 會在一組政策中封裝 OAuth 1.0a 和 OAuth 2 功能。權杖和密鑰的生命週期管理,包括產生、驗證和儲存空間,由 Apigee Edge 代表您的後端服務代管。

這份文件會指定 OAuth 政策定義的流程變數。這些變數可用於針對 OAuth 流程實作自訂行為。如要瞭解 OAuth 的使用方式,請參閱 OAuth

OAuth 2.0 流程變數

系統執行各個 OAuth 政策時,就會填入本表格中定義的流程變數,因此也能提供給在 API Proxy 流程中執行的其他政策或應用程式。

驗證存取權杖政策
  • 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 權杖。

根據預設,存取權杖必須透過授權 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 規格擷取值。

屬性值是由指定流程變數以動態方式產生,或在政策中使用預設值以靜態方式產生。

如果同時指定兩者,流程變數會優先採用。

產生隱含授權類型的存取權杖政策
成功時設定的變數:
  • 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 Proxy 流程中執行的其他政策或應用程式。

產生要求權杖政策

範例政策:

<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