V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rqxiao
V2EX  ›  程序员

SpringSecurityOAuth 访问 oauth/authorize 会被拦截

  •  
  •   rqxiao · 2020-01-22 13:29:58 +08:00 · 3032 次点击
    这是一个创建于 1549 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在代码中有配置"/oauth/*" 不需要登录认证

                .and()
                .authorizeRequests()//对下面请求
                .antMatchers("/authentication/require","/oauth/*"
                        ,securityProperties.getBrowser().getLoginPage()
                        ,"/code/*").permitAll()//对这些个请求不需要身份验证
                .anyRequest()//任何请求
                .authenticated()//都需要认证 /登录
    
    第 1 条附言  ·  2020-01-22 14:08:03 +08:00
    登录了才能可以访问到
    第 2 条附言  ·  2020-01-22 14:17:48 +08:00
    这段代码是写在 实现了 WebSecurityConfigurerAdapter 里的 configure 方法中的
    3 条回复    2020-01-23 11:48:20 +08:00
    skypyb
        1
    skypyb  
       2020-01-22 18:56:00 +08:00   ❤️ 1
    实现入参是 WebSecurity 这个参数的方法:configure(WebSecurity web)
    然后方法体内书写
    web.ignoring().antMatchers(HttpMethod.POST,"/oauth/*");

    试一下
    rqxiao
        2
    rqxiao  
    OP
       2020-01-23 10:43:53 +08:00
    @skypyb 额 查了半天说貌似 SpringSecurityOAuth 的授权码模式 获取授权码(/oauth/authorize )这一步是需要登录(例如 httpbasic 方式)的,密码模式( password )就是直接传账密获取 token,就只有一步了,不需要登录
    也有可能我说的不太对
    hantsy
        3
    hantsy  
       2020-01-23 11:48:20 +08:00
    @rqxiao 用 Code Flow 的时候, /oauth/* 需要 ClientId,ClientSecret,这个一般通过 HttpBasic 传递,也可以通过 Form 参数方式(一般可配置)。

    Resource owner Password Flow 不是所有的 IdP 都支持,一般 Authorization Code Flow 最常见。Client Credentials 设计用 Client 操作。Implicit 是简化的 Code, 很多 IDP 认为有安全问题,不支持。

    https://oauth.net/2/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   924 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:11 · PVG 06:11 · LAX 15:11 · JFK 18:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.