簡體   English   中英

Spring Oauth2 CORS問題

[英]Spring Oauth2 CORS issue

我將CORS設置為允許一些自定義標頭。 以下是響應標題-

響應標題{“日期”:“ 2016年3月14日星期一10:11:59 GMT”,
“服務器”:“ Apache-Coyote / 1.1”,“傳輸編碼”:“塊”,
“ Access-Control-Max-Age”:“ 3600”,“ Access-Control-Allow-Methods”:“ POST,GET,OPTIONS,DELETE,PUT”,“ Content-Type”:“ application / json”,“訪問-Control-Allow-Origin“:” *“,
“ Access-Control-Allow-Credentials”:“ true”,
“ Access-Control-Allow-Headers”:“ X請求的方式,授權,內容類型,Authorization_Code,User_Credentials,Client_Credentials”}

上面的響應標頭應該意味着可以使用以下標頭從所有來源使用API​​: Authorization, Content-Type, Authorization_Code, User_Credentials, Client_Credentials

我可以傳遞所有標頭,並使用所有來源的API。

問題-

不允許使用帶有授權API的請求。 授權是這樣傳遞Oauth令牌的標頭Authorizatio = Bearer ct45tg4g3rf3rfr5freg34gerfgr3gf (Bearer令牌)。

corsclient.js:609選項http://54.200.113.97:8080/supafit-api/users sendRequest @ corsclient.js:609(匿名函數)@ corsclient.js:647b.event.dispatch @ jquery-1.9.1.min .js:3v.handle @ jquery-1.9.1.min.js:3 / client#?client_method = GET&client_credentials = false&client_headers = Authoriz…nable = true&server_status = 200&server_credentials = false&server_tabs = remote:1 XMLHttpRequest無法加載http://54.200。 113.97:8080 / supafit-api / users 對預檢請求的響應未通過訪問控制檢查:請求的資源上不存在“ Access-Control-Allow-Origin”標頭。 因此,不允許訪問來源“ http://client.cors-api.appspot.com ”。 響應的HTTP狀態碼為401。

編輯:

這是該API的其余客戶端測試-

響應標題-

Server: Apache-Coyote/1.1 
Cache-Control: no-cache, no-store, max-age=0, must-revalidate 
Pragma: no-cache 
Expires: 0
X-XSS-Protection: 1; mode=block 
X-Frame-Options: DENY
X-Content-Type-Options: nosniff 
Access-Control-Allow-Origin: http://client.cors-api.appspot.com 
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT 
Access-Control-Max-Age: 3600
Access-Control-Allow-Credentials: true 
Access-Control-Allow-Headers: X-Requested-With 
Access-Control-Allow-Headers: Authorization
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Headers: Authorization_Code
Access-Control-Allow-Headers: User_Credentials
Access-Control-Allow-Headers: Client_Credentials 
Content-Type: application/json 
Transfer-Encoding: chunked 
Date: Mon, 14 Mar 2016 11:19:42 GMT Raw JSON

JSON響應正文-

{“ id”:78,“ userId”:“ 3465434567”,“ coachId”:null,
“名稱”:“ XDCDSC”,“ dob”:空,“電子郵件”:“ puneetpandey37@gmail.com”,“ imageURL”:“ https://lh5.googleusercontent.com/-TcTQeitAvag/AAAAAAAAAAI/AAA/4pamurzO1a4/ photo.jpg “,” gender“:null,” userPhysic“:null,” userTypeId“:1,
“ dietitanId”:空,“ alternateEmailId”:空,
“ yearsOfExperience”:空,“ lastExperience”:空,
“ Known語言”:空,“ aboutYourself”:空,
“ coreCompetence”:null,“ fieldOfWork”:null,“ userAddresses”:[
{
“ id”:1,“ userId”:78,“ locationId”:1,“ address”:“ EC”,“ landmark”:“ Near BN”,“ phoneNumber”:null,“ addressType”:“ Home”}] , “電話號碼”:[

]}

響應的HTTP狀態碼為401。

您的服務器需要對預檢請求進行身份驗證,但是客戶端會按照CORS規范中的說明刪除憑據:

否則,請發出預檢請求 使用方法OPTIONS ,並使用以下附加約束,將引用者來源作為具有手動重定向標志塊cookie標志集的 替代引用者來源的 原始來源來源獲取請求URL:

包括一個Access-Control-Request-Method標頭,並將請求方法作為標頭字段值(即使是簡單方法也是如此)。

如果作者請求標頭不為空,則包括一個Access-Control-Request-Headers標頭,並以字母順序將按字母順序排列的作者請求標頭中的標頭字段名的列表以逗號分隔,作為標頭字段值,每個都轉換為ASCII小寫(即使一個或多個更多是一個簡單的標題)。

  • 排除作者請求標頭。

  • 排除用戶憑據。

  • 排除請求實體主體。

您必須更改服務器,以允許匿名訪問預檢請求。

暫無
暫無

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

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