【发布时间】:2021-12-18 06:11:13
【问题描述】:
我已经在 Spring Boot 项目中集成了 IdentityServer4。
我想知道如何添加code_verifier来调用IdentityServer的“/connect/token”?
我在重定向网址中收到如下代码,
我在我的项目中构造了一个resttemplate来调用“/connect/token”
POST /connect/token CONTENT-TYPE application/x-www-form-urlencoded
client_id=client_id&
client_secret=secret&
grant_type=authorization_code&
code=returned_code&
redirect_uri=https://127.0.0.1:9443/signin-oidc
code_verifier=<this_encrypted_text>
在 requestBody 中我设置了 code_verifier=
供您参考 SecurityConfig 类是这样的
@EnableWebSecurity
public class ConfigSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
PortMapperImpl portMapper = new PortMapperImpl();
portMapper.setPortMappings(Collections.singletonMap("9443","9443"));
PortResolverImpl portResolver = new PortResolverImpl();
portResolver.setPortMapper(portMapper);
LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint(
"/login");
entryPoint.setPortMapper(portMapper);
entryPoint.setPortResolver(portResolver);
http.exceptionHandling()
.authenticationEntryPoint(entryPoint)
.and()
.authorizeRequests()
.antMatchers("/login","/css/*", "/images/*","/signin-oidc","/test")
.permitAll()
.anyRequest()
.authenticated()
.and()
.oauth2Login()
.loginPage("/login")
.and()
.logout().logoutUrl("/logout")
.logoutSuccessHandler(oidcLogoutSuccessHandler());
}
@Autowired
private ClientRegistrationRepository clientRegistrationRepository;
private LogoutSuccessHandler oidcLogoutSuccessHandler() {
OidcClientInitiatedLogoutSuccessHandler oidcLogoutSuccessHandler =
new OidcClientInitiatedLogoutSuccessHandler(
this.clientRegistrationRepository);
oidcLogoutSuccessHandler.setPostLogoutRedirectUri(
URI.create("http://localhost:9443"));
return oidcLogoutSuccessHandler;
}
}
而我的application.yml如下,
server:
port: 9443
ssl:
key-store: classpath:asif1.jks
key-store-password: xxxxx
key-store-type: pkcs12
key-store-alias: server
spring:
security:
oauth2:
client:
registration:
idsrv4:
client-name: client_name_test
client-id: client_id_test
client-secret: Marines
client-authentication-method: none
authorization-grant-type: authorization_code
redirect-uri: "https://127.0.0.1:9443/signin-oidc"
scope: "id_number,openid,email,roles,profile"
provider:
idsrv4:
authorization-uri: https://idsrv4test.com/connect/authorize
issuer-uri: https://idsrv4test.com
token-uri: https://idsrv4test.com/connect/token
user-info-uri: https://idsrv4test.com/connect/userinfo
user-name-attribute: sub
jwk-set-uri: https://idsrv4test.com/.well-known/openid-configuration/jwks
有什么帮助吗?
【问题讨论】:
标签: spring spring-boot oauth-2.0 identityserver4 spring-oauth2