簡體   English   中英

Spring 引導 OAuth2 登錄未執行任何操作

[英]Spring Boot OAuth2 login not doing anything

我正在嘗試讓用戶 session 通過 OAuth2 提供程序進行管理,並且我進行了自定義登錄以進行調用,設置 cookies 等......但后來我意識到Spring Boot Security 具有 OAuth2 集成,我決定從頭開始並以正確的方式去做。

問題是,對於我訪問的任何安全路徑,我都被重定向到該服務,我在那里登錄,然后我被重定向回我的回調 url,代碼作為參數,我像往常一樣得到模板,去通過 controller,我的申請在任何時候都沒有獲得授權

在此處輸入圖像描述

在我使用此代碼訪問 API 之前,但據我所知,現在Spring 應該在管理它

因此,我進行了身份驗證,我再次被重定向到我的頁面(所有用戶都允許我的回調 url),然后我在同一個地方,沒有以任何方式進行身份驗證。 我無法訪問任何安全路徑。

我做了什么

應用程序.yml:

security:
    oauth2:
      client:
        registration:
          wca:
            client-id: 0YekXxbT20En0V000000Tk9pGam2K9HvIA0fTPP0
            client-secret: cm0001232132132132hGNICxzAwNKqFMg
            authorization-grant-type: authorization_code
            redirect-uri: '{baseUrl}/loginWCA'
        provider:
           wca:
             authorization-uri: https://www.worldcubeassociation.org/oauth/authorize
             token-uri: https://www.worldcubeassociation.org/api/v0/me

安全配置:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{


    @Override
    protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests().antMatchers("/loginWCA").permitAll().anyRequest().authenticated().and().oauth2Login();
    }

免責聲明:我知道我正在保護一切,我的目標是將 go 轉到根路徑 -> 重定向到提供商 -> 登錄 -> 返回我的 web -> 有一個有效的 session 來訪問根路徑作為經過身份驗證的用戶。

您應該在登錄通過后獲得令牌。 請參考您的 oauth2 提供商。 然后在請求 HEADER 'Authentication' 中使用 Bearer 添加它。 所以其他頁面不需要認證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM