我正在尝试改编非常好的示例spring-webmvc-pac4j-boot-demo。 我使用 PAC4J 和 Spring MVC 对这个工作示例做了一些小改动,以使用一些 OIDCclient 请求 OKTA 托管登录页面 我希望被重定向到 okta 登录页面,并在成功登录后被授予所请求的页面。但我却收到了 HTTP 400
我在okta部分的参数是:
Sign-in redirect URIs = http://localhost:8080/oidc
Sign-out redirect URIs = http://localhost:8080
Initiate login URI = http://localhost:8080/callback
在应用程序代码(Pac4jConfig.java): 我创建了一个 Oidc 配置:
final OidcConfiguration oidcConfiguration = new OidcConfiguration();
oidcConfiguration.setClientId("my client ID");
oidcConfiguration.setSecret("big big secret");
oidcConfiguration.setDiscoveryURI("https://myforeverhostatokta.okta.com/oauth2/default/.well-known/openid-configuration");
final OidcClient oidcClient = new OidcClient(oidcConfiguration);
oidcClient.setCallbackUrl("http://localhost:8080/callback");
...
and i created an interceptor (SecurityConfig.java):
...
registry.addInterceptor(buildInterceptor("OidcClient")).addPathPatterns("/oidc/*");
当我运行修改后的示例并请求 localhost:8080/oidc 时,我重定向到我的 OKTA 服务器,并显示一个 HTTP 400 错误页面,声称我的客户端应用程序应该在其中设置一些重定向 uri。 我坚持这一点是因为我不知道我到底应该在 pac4j 配置中的哪里设置这个重定向 uri。 对于这个问题有任何帮助或见解吗?
我在 Okta 开发者博客上写了一篇 使用 Java EE 和 OIDC 构建 Java REST API 教程,应该会有所帮助。具体来说,使用 Pac4j 锁定您的 Java REST API 部分。
您还可以克隆 GitHub 存储库并查看代码:
git clone -b pac4j https://github.com/oktadev/okta-java-ee-rest-api-example.git