【问题标题】:Spring OAuth2 token without ClientId and ClientSecret for External Clients没有用于外部客户端的 ClientId 和 ClientSecret 的 Spring OAuth2 令牌
【发布时间】:2017-10-06 12:27:55
【问题描述】:

我们使用 Spring 生成 OAuth 令牌,它接受用户名/密码/ClientId/Secret,效果很好。对于外部客户端,我们只需要输入用户名和密码并生成 OAuth Token。

<security:http pattern="/oauth/token" create-session="stateless"
        authentication-manager-ref="clientAuthenticationManager"
        xmlns="http://www.springframework.org/schema/security">
        <security:intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
        <security:anonymous enabled="false" />
    <security:http-basic entry-point-ref="clientAuthenticationEntryPoint" />
        <!-- include this only if you need to authenticate clients via request parameters -->
        <security:custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER" />
    <security:access-denied-handler ref="oauthAccessDeniedHandler" />
  </security:http>

下面是我们需要添加的新代码,但它要求在浏览器中输入用户名和密码。

<security:http pattern="/**external**/oauth/token" create-session="stateless"
        authentication-manager-ref="clientAuthenticationManager"
        xmlns="http://www.springframework.org/schema/security">
        <security:intercept-url pattern="/external/oauth/token" access="IS_AUTHENTICATED_FULLY" />
        <security:anonymous enabled="false" />
    <security:http-basic entry-point-ref="clientAuthenticationEntryPoint" />
        <security:custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER" />
    <security:access-denied-handler ref="oauthAccessDeniedHandler" />
  </security:http>

请指导我们是否可以在没有clientId的情况下生成OAuth并在内部传递clientId来生成OAuth。

【问题讨论】:

    标签: spring oauth spring-security-oauth2


    【解决方案1】:

    如果没有 clientId,您永远无法生成 OAuth 令牌! Oauth2 有 3 种创建令牌的方法,隐式、代码和用户/通行证。最后一个应该避免,因为这意味着 Oauth 客户端将访问用户的凭据,而 OAuth 正是为了防止这种情况而构建的。仅使用用户的凭据授予隐式令牌(通常仅涉及浏览器)。在代码模式下,OAuth 客户端收到一个代码(不应在浏览器中),然后将其交换为令牌。令牌交换的代码要求 Oauth 客户端使用它的 clientId 和一个秘密进行身份验证,这通常使用基本身份验证来完成。

    【讨论】:

    • 同意你的观点,但我想要实现的是使用内部传递的 clientId 生成令牌,其中用户只通过 spring security xml 配置传递用户名和密码。
    • 您是在谈论发布隐式令牌吗?使用隐式授权,Oauth 客户端会将用户的浏览器重定向到服务器上的 /oauth/authorize。此 URL 受到保护,因此浏览器被重定向到登录页面,并且用户使用基于表单的身份验证进行身份验证。登录后,浏览器将显示批准页面,用户 r 批准/拒绝对 clientId 标识的应用程序的访问。 OAuth 客户端应该永远不会看到凭据,只有受信任的 OAuth 服务器应该看到,否则不需要使用 OAuth。
    【解决方案2】:

    我认为您需要的是 https://www.rfc-editor.org/rfc/rfc6749#section-1.3.3 中解释的资源所有者密码授权类型

    资源所有者密码授权类型只能用于受信任的客户端。因此,如果您所说的外部客户端是受信任的客户端(例如由同一家公司开发的原生移动应用程序。例如 Facebook 移动应用程序),则可以使用它。

    流程在https://www.rfc-editor.org/rfc/rfc6749#section-4.3.1中解释

    资源所有者授权类型最重要的方面是客户端不应存储用户名和密码。

    【讨论】:

      猜你喜欢
      • 2017-09-01
      • 2012-08-01
      • 2013-11-02
      • 2015-07-15
      • 1970-01-01
      • 2015-06-02
      • 2019-03-03
      • 2015-11-10
      • 2015-03-24
      相关资源
      最近更新 更多