我有受网守(louketo-proxy)保护的网络服务。当我通过 ajax 请求调用受保护的服务时,它不会将我重定向到登录页面。它向我显示消息“跨域请求被阻止:同源策略不允许在http://127.0.0.1:3000/app-name/api/getSession读取远程资源。(原因:CORS 标头 'Access-Control-Allow -原点缺失)。”
下面是网守配置文件:
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