首页 > 解决方案 > 使用 X509 的 SpringOauth 令牌

问题描述

我正在做一个项目,其中两种类型的客户端需要身份验证令牌。- 物联网设备 - 网络客户端

Web 客户端遵循典型套件,而 IOT 设备提供证书进行身份验证,我如何使用 AuthorizationServerConfigurerAdapter 来生成 TOKEN,除了 formlogin 路由。

   MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
   params.add("grant_type", "password");
   this.mockMvc.perform(post("/oauth/token")
            .params(params)
            .with(httpBasic("clientID","clientSecret"))
            //.with(x509("client.crt"))
            .accept("application/json;charset=UTF-8"))
            .andExpect(status().isOk()).andDo(log());

什么时候

public class WebSecurity extends WebSecurityConfigurerAdapter {

//@Autowired
//private X509CustomAuthenticationProvider authenticationProvider;


@Override
protected void configure(HttpSecurity http) throws Exception {
    // @formatter:off
     http
     .authorizeRequests().antMatchers("/api/**").fullyAuthenticated()
     .and()
        .x509()
     .and()
        .formLogin()

     .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
     .and()
         .csrf().disable();
    // @formatter:on
}

问题是如果不是授权服务器网络安全工作正常,只要我启用

  @EnableAuthorizationServer
  @Configuration
  public class AuthorisationServerConfiguration extends 
  AuthorizationServerConfigurerAdapter {

它开始投掷

{"error":"invalid_grant","error_description":"凭证错误"}

在处理令牌请求之前,我需要从证书中提取用户名密码

标签: spring-securityspring-oauth2

解决方案


推荐阅读