授权码,无需使用表单登录

问题描述 投票:0回答:1

我目前正在使用 spring boot Oauth2 授权服务器。授权类型是授权码。 无论如何,我可以避免使用表单登录作为授权代码授予类型吗?

我可以对授权端点进行休息呼叫吗?

有什么我可以参考的吗?

以下面为例,假设client_id是client,client_secret是secret

http://localhost:8080/oauth2/authorize?response%5C_type=code&client%5C_id=client&redirect%5C_uri=http://127.0.0.1:8080/login/oauth2/code/oidc-client&scope=openid

如果上述方法不可行,

那么是否可以向登录表单添加更多字段,并且不仅基于客户端 ID 和客户端密钥,还基于这些字段的状态进行验证 举个例子

员工姓名:测试员工 员工年龄:17岁 客户编号: 客户 客户秘密:秘密

首先我想检查数据库中是否存在 TestEmployee 那么我想确保他的年龄超过 25 岁

如果没有,那么我想显示登录验证异常...... 这可能吗?

我尝试使用媒体类型作为应用程序json,但它似乎不起作用

 http
                .securityMatcher(endpointsMatcher)
                .authorizeHttpRequests((authorize) -> authorize
                        .anyRequest().authenticated()
                )
                .csrf(csrf -> csrf.ignoringRequestMatchers(endpointsMatcher))
                .oauth2ResourceServer(resourceServer -> resourceServer
                        .jwt(Customizer.withDefaults())
                )
                .exceptionHandling((exceptions) -> exceptions
                        .defaultAuthenticationEntryPointFor(
                                new LoginUrlAuthenticationEntryPoint("/login"),
                                **new MediaTypeRequestMatcher(MediaType.APPLICATION_JSON)**
                        )
                )
                .apply(authorizationServerConfigurer);
spring-oauth2 spring-authorization-server
1个回答
0
投票

我是否可以避免使用表单登录作为授权代码授予类型?

无法绕过

authorization_code
流程中的登录表单。

那么可以在登录表单中添加更多字段吗?

是的,这是可能的。检查:https://github.com/spring-projects/spring-authorization-server/issues/533

对于验证,您可能需要实现自定义

AuthenticationProvider
。查看本文以获得一些指导。

© www.soinside.com 2019 - 2024. All rights reserved.