我使用https://github.com/pac4j/spring-webflux-pac4j-boot-demo与spring引导和webflux使用pac4j做OIDC认证。我正在使用自定义回调url设置OIDC客户端。
访问/authenticate
时,被带到IDP提供商处登录,登录后被重定向到回调URl。但是,回调url返回404
。
默认回调/callback
仍然有效。如果您尝试向/callback
发送GET请求,则记录回调逻辑是如何执行的。为什么回调url更改(使用setCallbackUrl
)不工作?
2023-01-15 21:27:04.417 DEBUG 442814 --- [or-http-epoll-3] o.p.core.engine.DefaultCallbackLogic : === CALLBACK ===
2023-01-15 21:27:05.995 DEBUG 442814 --- [or-http-epoll-3] o.p.core.engine.DefaultCallbackLogic : foundClient: #OidcClient# |....
...
Pac4jConfig.java[此处为原始文件]
package io.company.auth;
import java.util.Optional;
import org.pac4j.core.client.Clients;
import org.pac4j.core.config.Config;
import org.pac4j.core.matching.matcher.PathMatcher;
import org.pac4j.springframework.web.SecurityFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.WebFilter;
import org.pac4j.oidc.client.OidcClient;
import org.pac4j.oidc.config.OidcConfiguration;
@Configuration
// to define the callback and logout controllers
@ComponentScan(basePackages = "org.pac4j.springframework.web")
public class Pac4jConfig {
@Bean
public Config config() {
OidcConfiguration config = new OidcConfiguration();
config.setClientId("my_client_id");
config.setSecret("my_secret");
config.setDiscoveryURI("idp_dicovery_url");
config.setScope("openid");
config.setUseNonce(false);
OidcClient oidcClient = new OidcClient(config);
oidcClient.setName("ABCDapp");
oidcClient.setCallbackUrl("http://localhost:8081/api/oidc/cb?client_name=abcd");
final Clients clients = new Clients("http://localhost:8081/api/oidc/cb?client_name=abcd", oidcClient);
return new Config(clients);
}
@Bean
public WebFilter protectedFilter() {
return SecurityFilter.build(config(), new PathMatcher().includePath("/authenticate"));
}
}
在/callback
端点上自动设置CallbackController
。不过,您可以使用pac4j.callback.path
属性更改这一点。见:https://github.com/pac4j/spring-webflux-pac4j/blob/master/src/main/java/org/pac4j/springframework/web/CallbackController.java L46