定义 OAuth 服务提供者

OAuth 服务提供者是指定用于 OAuth 的配置选项集。在对授权和令牌端点的入站请求的 URL 中指定提供者的 id 或名称。处理请求时将使用该提供者的配置选项集。此过程允许一个带有一个端点 servlet 的服务器有效地提供多项 OAuth 配置。例如,使用定义给 OAuth 提供者 photoShare 的 OAuth 配置选项集来处理 https://my.company.com:8021/oauth2/endpoint/photoShare/authorize URL。使用定义给 OAuth 提供者 calendarAuthz 的 OAuth 配置选项集来处理 https://my.company.com:8021/oauth2/endpoint/calendarAuthz/authorize URL。

关于此任务

使用 server.xml 文件中的 oauthProvider 元素来定义 OAuth 服务提供者。要定义 OAuth 服务提供程序,您可以编辑 server.xml 文件或者使用用于 Liberty 的 WebSphere® Application Server Development Tools。本任务描述如何定义最低 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 功能部件时自动启动。但是,必须将已认证的角色映射到一个或多个用户、组或特殊主体集。提供了另一个角色 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. 定义用户注册表,可为 LDAP 注册表(通过指定 ldapRegistry-3.0 功能部件和 ldapRegistry 配置元素来定义)或者基本注册表(通过指定 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>

用于指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: Monday, 5 December 2016
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-libcore-mp&topic=twlp_oauth_defining
文件名:twlp_oauth_defining.html