你好,我正在搜索使用PKCE做应用程序的hoxw
这是文件: pom.xml
enter code here
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!-- !!!!!!!!! -->
<!-- Bases de données -->
<!-- JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-jwt</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
....
现在是application.yaml
spring:
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: http://localhost:8080/auth/realms/monteleservice/protocol/openid-connect/certs
... and some other configuration (datasource, ...)
资源服务器
@EnableWebSecurity
公共类ResourceServerConfiguration扩展了ResourceServerConfigurerAdapter { @Autowired 环境env;
@Override
public void configure( HttpSecurity http) throws Exception {
/*http.cors()
.and().authorizeRequests()
.antMatchers("/").permitAll();*/
http.cors().and()
.authorizeRequests()
.mvcMatchers("/test/**").denyAll()
.and()
.oauth2ResourceServer()
.jwt();
}
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
List<String> lst =new ArrayList<>( );
lst.add( env.getProperty( "web-client.url" ) );
configuration.setAllowedOrigins(lst);
configuration.setAllowedHeaders( Arrays.asList( "Authorization","Content-Type","Accept", "X-Requested-With", "remember-me" ));
configuration.setAllowedMethods( Arrays.asList( "POST", "GET", "PUT", "OPTIONS", "DELETE"));
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
休息控制器
@RestController
@RequestMapping(path = "/test")
public class TestCtrl {
@RequestMapping("/")
public void getTest() {
}
}
我的请求:http://localhost:8001/test/
现在我的角度错误
错误invalid_token ERROR_DESCRIPTION无效的访问令牌:eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJoNktOcjFnel85ZzV6dVJXRnpxVzVnQmVxNjBFOVdfS3Y3Vzk4Um5RNDJvIn0.eyJqdGkiOiI3NDQ0N2JkYy04ZDRjLTQ0NGEtOTczMS1lZWQxMmE4MzNiYWYiLCJleHAiOjE1NzU0NzgwNjAsIm5iZiI6MCwiaWF0IjoxNTc1NDc3OTQwLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvbW9uVGVsZVNlcnZpY2UiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiYWFlNzgwOTctNmRhNi00MTA5LTg3YTEtZjQ2YjljYzYxNjAwIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibW9udGVsZXNlcnZpY2UiLCJub25jZSI6Ik4wLjc1MTk5NzM1NTMzMDU4NjUxNTc1NDc3OTQwNT ... wcm9maWxlIHJvbGVzIGVtYWlsIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsInByZWZlcnJlZF91c2VybmFtZSI6ImRhbWllbi5wb2xpenppQGdtYWlsLmNvbSIsImVtYWlsIjoiZGFtaWVuLnBvbGl6emlAZ21haWwuY29tIn0.vjLo-hjnZX_8vesAs3tVZaBxpzQvB9G-f7dUwD2C4acKDZN6pkRrykFW7Abx7dwJWIWD8anRnbag9xhTpKHdl8YNVq0MUClwoQGNLXLQMfm318v7kZoPz73rSpSCUo4x_qPimSU_gyCEM0xilwrLCpscuXROiQlC8ky3XUBkbV8bUo1ITUf3y5nNKCKPbi7BLX2ZcPZrH8bfLrUB9LUw2vjvp2bkTDtukOddRyC_U4s1WOGAiPDn5L4yrnZgvBIxv779bjrmSXNNf-Habcc84hO0kR6fHMXUDBYDxWA6 kv1ifXt256gN1N6lPBKUTx5qvckVEAHjMQZyPJmieC0psg
有人可以帮助我吗? 谢谢