定義 OAuth 服務提供者

OAuth 服務提供者是 OAuth 的一組具名配置選項。 提供者的 id 或名稱指定在授權和記號端點之入埠要求的 URL 中。 當處理要求時,會使用這個提供者的配置選項集。 這個程序使含有單一端點 Servlet 的伺服器能夠有效提供多重 OAuth 配置。比方說,https://my.company.com:8021/oauth2/endpoint/photoShare/authorize URL 就是利用定義給名稱為 photoShare 之 OAuth 提供者的該組 OAuth 配置選項來進行處理。https://my.company.com:8021/oauth2/endpoint/photoShare/authorize URL 則是利用定義給名稱為 calendarAuthz 之 OAuth 提供者的該組 OAuth 配置選項來進行處理。

關於這項作業

OAuth 服務提供者是利用 server.xml 檔中的 oauthProvider 元素來定義。 您可以編輯 server.xml 檔,或利用 Liberty 設定檔的 WebSphere® Application Server 開發工具,來定義 OAuth 服務提供者。這項作業說明如何定義最小的 OAuth 配置。

程序

  1. 新增 oauth-2.0ssl-1.0 特性。 OAuth 是一個安全通訊協定,因此需要 SSL。 對於 Liberty 設定檔,您必須利用 keyStore 元素來提供 SSL 的金鑰儲存庫密碼。 金鑰儲存庫沒有預設的密碼。
    <featureManager>
      <feature>oauth-2.0</feature>
      <feature>ssl-1.0</feature>
    </featureManager>
  2. 利用 oauth-roles 元素來設定 OAuth Web 應用程式的角色對映。 OAuth 是一個 HTTP 型通訊協定,另外還提供一個 Web 應用程式來處理授權和記號端點。 Web 應用程式是內建的,當您指定 oauth-2.0 特性時,會自動啟動。 不過,您必須將 authenticated 角色對映至一或多個使用者、群組或特殊主體。 另外還提供一個用來管理用戶端配置的 clientManager 角色,但 OAuth 授權的運作並不需要對映這個角色。
    <oauth-roles>
      <authenticated>
        <user>testuser</user>
      </authenticated>
    </oauth-roles>
  3. 利用 oauthProvider 元素來定義一或多個提供者。 提供者必須定義至少一個用戶端。 用戶端可以用 localStoreclient 元素定義在本端。 用戶端也可以透過 databaseStore 元素定義在關聯式資料庫中。
    <oauthProvider id="SampleProvider" filter="request-url%=ssodemo">
      <localStore>
        <client name="client01" secret="{xor}LDo8LTor"
                displayname="Test client number 1"
                redirect="http://localhost:1234/oauthclient/redirect.jsp"
                enabled="true" />
      </localStore>
    </oauthProvider>
  4. 定義一個使用者登錄,可以是指定 ldapRegistry-3.0 特性和 ldapRegistry 配置元素來定義 LDAP 登錄,或是指定 basicRegistry 配置元素來定義基本登錄。
    <basicRegistry id="basic" realm="BasicRealm">
      <user name="testuser" password="testuserpwd" />
    </basicRegistry>
  5. allowFailOverToBasicAuth Web 應用程式安全內容設為 true
    <webAppSecurity allowFailOverToBasicAuth="true" />

結果

您已定義最小 OAuth 配置。

範例

下例顯示一個範例 server.xml 檔,其定義了含有一個用戶端的簡式 OAuth 提供者:
<server>

  <featureManager>
    <feature>oauth-2.0</feature>
    <feature>ssl-1.0</feature>
  </featureManager>

  <keyStore password="keyspass" />

  <oauth-roles>
    <authenticated>
      <user>testuser</user>
    </authenticated>
  </oauth-roles>

  <oauthProvider id="SampleProvider" filter="request-url%=ssodemo">
    <localStore>
      <client name="client01" secret="{xor}LDo8LTor"
              displayname="Test client number 1"
              redirect="http://localhost:1234/oauthclient/redirect.jsp"
              enabled="true" />
    </localStore>
  </oauthProvider>

  <webAppSecurity allowFailOverToBasicAuth="true" />

  <basicRegistry id="basic" realm="BasicRealm">
    <user name="testuser" password="testuserpwd" />
  </basicRegistry>

</server>

指示主題類型的圖示 作業主題

資訊中心條款 | 意見


「時間戳記」圖示 前次更新: 2015 年 6 月 22 日
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_oauth_defining
檔名:twlp_oauth_defining.html