2017-02-12 58 views
1

我们使用Spring接受OAuth令牌生成,它接受用户名/密码/ ClientId/Secret,这非常完美。对于外部客户端,我们只需输入用户名和密码并生成OAuth令牌。没有ClientId和ClientSecret的外部客户端的Spring OAuth2令牌

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

回答

1

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

+0

同意你的观点,但我想实现的是使用内部传递的clientId生成令牌,其中用户只通过spring security xml配置传递用户名和密码。 – Rahul

+0

您是否在谈论发布隐式令牌?通过隐式授予,Oauth客户端将把用户的浏览器重定向到服务器上的/ oauth/authorize。该URL受到保护,因此浏览器被重定向到登录页面,用户使用基于表单的身份验证进行身份验证。登录后,浏览器将显示批准页面,用户r批准/拒绝clientId标识的应用程序的访问。 OAuth客户端不应该看到凭据,只有受信任的OAuth服务器应该,否则不需要使用OAuth。 –

0

我想你需要的是这是在https://tools.ietf.org/html/rfc6749#section-1.3.3

资源所有者密码交付式解释应该只与可信客户机使用的资源所有者密码交付式。因此,如果您所说的外部客户端是可信的客户端(如同一家公司开发的原生移动应用程序,例如Facebook Mobile App),则可以使用该客户端。

流在https://tools.ietf.org/html/rfc6749#section-4.3.1

解释资源所有者交付式的最重要的方面是客户不应该存储用户名和密码。

相关问题