无法通过Ajax请求调用受网守密钥隐藏保护的Web服务

时间:2020-09-02 07:39:52

标签: keycloak keycloak-gatekeeper louketo-proxy

我的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

enter image description here

1 个答案:

答案 0 :(得分:1)

您尝试定义一些允许的CORS来源,例如

header

尝试如果您允许所有操作会发生什么?