• 请不要在回答技术问题时复制粘贴 AI 生成的内容
rqxiao
V2EX  ›  程序员

SpringSecurityOAuth 访问 oauth/authorize 会被拦截

  •  
  •   rqxiao · Jan 22, 2020 · 3544 views
    This topic created in 2332 days ago, the information mentioned may be changed or developed.

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

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

    试一下
    rqxiao
        2
    rqxiao  
    OP
       Jan 23, 2020
    @skypyb 额 查了半天说貌似 SpringSecurityOAuth 的授权码模式 获取授权码(/oauth/authorize )这一步是需要登录(例如 httpbasic 方式)的,密码模式( password )就是直接传账密获取 token,就只有一步了,不需要登录
    也有可能我说的不太对
    hantsy
        3
    hantsy  
       Jan 23, 2020
    @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/
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1039 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:44 · PVG 06:44 · LAX 15:44 · JFK 18:44
    ♥ Do have faith in what you're doing.