Spring Security:OAuth 2.0登录:绕过登录页面 [英] Spring Security: OAuth 2.0 Login: Bypass login page

查看:23
本文介绍了Spring Security:OAuth 2.0登录:绕过登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以完全跳过登录页面(默认/自定义),直接转到授权端点进行身份验证:

@EnableWebSecurity
public class OAuth2LoginSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .oauth2Login()
                .loginPage("/login/oauth2")
                ...
                .authorizationEndpoint()
                    .baseUri("/login/oauth2/authorization")
                    ....
    }
} 

推荐答案

我无法删除Spring Security的默认/自定义登录页面,但作为一种解决办法,我在登录页面上添加了重定向,这样最终用户永远不会知道中间有登录页面。

@RequestMapping(value = "/login/oauth2", method = { RequestMethod.POST, RequestMethod.GET })
public ModelAndView loginPage() {
    Map<String, Object> model = new HashMap<>();
    return new ModelAndView("redirect:/oauth2/authorization/google", "model", model);
}

这篇关于Spring Security:OAuth 2.0登录:绕过登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆