OAuth 流程變數

您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

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 權杖。

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

屬性值是從指定的流程變數動態衍生,或是使用政策中的預設值靜態衍生。

如果兩者皆指定,則以流程變數為優先。

為隱含授權類型產生存取權杖政策
成功時設定的變數:
  • 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