簡體   English   中英

Spring Security JWT - Postman authentication through Authorization header works but from my Angular front end doesn't work

[英]Spring Security JWT - Postman authentication through Authorization header works but from my Angular front end doesn't work

I have a web application with Java, Spring Boot and Spring Security on the backend, and Angular on the front end.

我已經使用 Spring Security 實現了登錄,並且身份驗證似乎有效 - 在 Postman 以及我的應用程序的前端中,我收到了 jwt 令牌。 兩個令牌似乎都是正確的,因為無論我使用在 Postman 還是在前端獲取的令牌,當我在授權 header 中向服務器發出其他請求時發送這些令牌中的任何一個時,我的應用程序的后端都會接受該令牌我從服務器收到 200 OK 響應。

但這里是 go 的不同方式:我的請求只有在我從 Postman 發送時才被授權。 當我從我的應用程序的前端發送(我認為)相同的請求時,后端會拋出 403 disabled 自然地,我假設我必須從前端發送請求,而不是從 Postman 發送請求,但我找不到任何區別。 據我所知,我發送了相同的方法、相同的正文、相同的標頭(使用授權令牌)

你知道那里可能發生什么嗎?

原因是我需要在 class 擴展 WebSecurityConfigurerAdapter 的 Spring Security 中啟用 cors:

protected void configure(HttpSecurity http) throws Exception {
    http
            .cors().and()

暫無
暫無

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

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