我有一个相当基本的 Spring Boot 设置,我已经安装了 Spring Security,并且我已经成功地设置了 OAuth2 来保护我的 API。
几天前我遇到了一些麻烦,问(并回答)了一个关于达到我的/oauth/token终点的问题。我很快就发现问题在于我试图在我的POST请求正文中发送我的客户端凭据,但在 Spring Security 中配置了令牌端点以通过 HTTP 基本身份验证接受客户端凭据(client_id和secret)。
我使用 OAuth2 API 的大部分经验都涉及在POST请求正文中发送客户端凭据,我想知道是否可以将 Spring Security 配置为以相同的方式运行?
我尝试了一些不同的事情但没有成功,比如设置以下配置选项,但我觉得这可能只在配置 OAuth2 客户端时使用:
security.oauth2.client.clientAuthenticationScheme=form
这是我的授权服务器配置。
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.approval.UserApprovalHandler;
import org.springframework.security.oauth2.provider.token.TokenStore;
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private TokenStore tokenStore;
@Autowired
private UserApprovalHandler userApprovalHandler;
@Autowired
@Qualifier("authenticationManagerBean")
private AuthenticationManager authenticationManager;
@Autowired
private PasswordEncoder passwordEncoder;
相关分类