Tôi mới sử dụng CORS và đã biết rằng yêu cầu preflight preflight được gửi bởi trình duyệt loại trừ thông tin đăng nhập của người dùng. Làm cách nào để nhận bộ lọc (trong httpd.conf) phản hồi các yêu cầu OPTIONS khác nhau, tức là bỏ qua xác thực?CORS - cách bỏ qua xác thực cho OPTIONS yêu cầu preflight trong httpd.conf của Apache?
Đây là cấu hình hiện tại của tôi:
<LocationMatch /api>
SetEnvIfNoCase Origin "https://(www\.)?(domain1\.com|domain2\.com)(:\d+)?$" AccessControlAllowOrigin=$0
Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials "true"
Header set Access-Control-Allow-Methods "GET,POST,DELETE,OPTIONS"
Header set Access-Control-Allow-Headers "Accept, Authorization, Origin, Content-Type"
AuthFormProvider ldap
AuthLDAPURL "ldap://localhost:10889/ou=Users,dc=work,dc=com?uid"
AuthLDAPGroupAttribute member
AuthLDAPGroupAttributeIsDN on
Require valid-user
ErrorDocument 401 /login.html
ErrorDocument 500 /error.html
AuthType form
AuthName realm
Session On
SessionMaxAge 1800
SessionDBDCookieName session path=/
ProxyPass http://localhost:8080 timeout=31536000
AuthFormFakeBasicAuth On
</LocationMatch>
Và javascript mà làm theo yêu cầu:
$.ajax({
type : "DELETE",
url : "https://www.domain1.com/api",
xhrFields: {
withCredentials: true,
},
success : function(data){
},
});
Tôi đã thử các follwoing nhưng không có may mắn:
(a)
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L,E=HTTP_ORIGIN:%{HTTP:ORIGIN}]
(b)
<Limit OPTIONS>
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Credentials "false"
Header always set Access-Control-Allow-Headers "Accept, Authorization, Origin, Content-Type"
Header always set Access-Control-Allow-Methods "GET,POST,DELETE,OPTIONS,PUT"
</Limit>
(c)
<Limit OPTIONS>
Allow for all
</Limit>
(d)
SetEnvIfNoCase Request_Method OPTIONS allowed
Bất kỳ ý tưởng? Hãy giúp tôi !
Trường hợp _is_ phần cấu hình yêu cầu auth ở địa điểm đầu tiên? – CBroe
'Cho phép cho tất cả' phải là _FROM_ thay vào đó, và bạn sẽ phải kết hợp nó với' SATISFY ANY', để chỉ thị 'ALLOW' hoặc' REQUIRE' áp dụng cho một yêu cầu 'OPTIONS'. – CBroe
Cảm ơn nhưng vẫn trả về 401 Không được ủy quyền. – user3802087