问题描述
我的Web服务受到网守(louketo-proxy)的保护。当我通过ajax请求调用受保护的服务时,它不会将我重定向到登录页面。它向我显示消息“跨域请求被阻止:同源策略禁止读取http://127.0.0.1:3000/app-name/api/getSession上的远程资源。(原因:CORS标头'Access-Control-Allow-Origin'丢失)。“
以下是网守配置文件:
client-id: app_id
client-secret: app_secret
discovery-url: http://127.0.0.1:8080/auth/realms/app_realm
redirection-url: http://127.0.0.1:3000
upstream-url: http://127.0.0.1:8043
enable-logging: true
enable-json-logging: true
verbose: true
enable-session-cookies: true
skip-upstream-tls-verify: true
skip-openid-provider-tls-verify: true
encryption-key: enc_key
listen: 0.0.0.0:3000
secure-cookie: false
enable-logging: true
enable-json-logging: true
enable-refresh-tokens: true
enable-session-cookies: true
enable-cors: true
cors-max-age : 1000
cors-headers:
- Accept
- Content-Type
- Cache-Control
- Pragma
- X-Custom-Header
- Source
debug: true
resources:
- uri: /app/api/v5/stylesheets/key=CSS
white-listed: true
- uri: /app/api/v5/images/key=FAVICON
white-listed: true
- uri: /app/api/v5/*
我正在使用的Keycloak版本是10.0.2
解决方法
您尝试定义一些允许的CORS来源,例如
header
尝试如果您允许所有操作会发生什么?