繁体   English   中英

CORS 已阻止从源“xxxx”访问“xxx/.well-known/openid-configuration”处的 XMLHttpRequest

[英]Access to XMLHttpRequest at 'xxx/.well-known/openid-configuration' from origin 'xxxx' has been blocked by CORS

我正在使用 okta oAuth 对 angular 8 应用程序进行身份验证和授权。 由于获取 ' https://dev-166545.okta.com/oauth2/aus1igd7yewoAs4xa357/.well-known/openid-configuration导致问题

可信来源

我在 okta 可信源中添加了重定向 URL。 由于公司政策,我无法在 CORS 中添加 URL。

我该如何解决 CORS 问题

Access to XMLHttpRequest at 'https://dev-166545.okta.com/oauth2/aus1igd7yewoAs4xa357/.well-known/openid-configuration' from origin 'https://localhost:44307' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

但是,在网络中我可以看到

在此处输入图片说明

首选选项是在 API/可信来源下将您的 Web 域添加到 Okta - 就像我写的第 7 步一样

单页应用程序身份验证流程所需的设置

需要 CORS 才能通过授权代码流 (PKCE)实现 SPA 的开放 id 连接到最新的安全标准。

OIDC 客户端中有一个替代选项,即避免提供授权 url 并显式提供重定向端点和令牌签名密钥。 我的 Azure 代码示例中,我通过显式提供令牌签名密钥来防止 JWKS 查找。

但是,您将被限制在不再推荐的隐式流程中,因此您削弱了应用程序的安全性 - 这不符合您公司的利益 - 并且还为您的代码增加了相当大的复杂性。

也许作为下一步我对您的利益相关者的回应 - 并尝试说服他们做更新到推荐的行业标准安全设置的明智之举

问题需要更多细节。 特别是预检请求/响应头,请求/响应头。 不要使用localhost (因为提到浏览器问题)和 http(因为使用 https 设置 prod 需要不同的 CORS 配置)。

原始卷曲预检测试:

curl -H "Origin: https://acme.com" \
 -H "Access-Control-Request-Method: GET" \
 -H "Access-Control-Request-Headers: X-Requested-With, :method" \
 -X OPTIONS -k https://dev-166545.okta.com/oauth2/aus1igd7yewoAs4xa357/.well-known/openid-configuration \
 --silent --verbose 2>&1 | grep Access-Control

=> 让您了解请求的内容和返回的内容。

Type CORS != type Redirect + valid origin is 例如http://localhost:8080而不是http://localhost:8080/ -> 不清楚你是如何配置 CORS 类型的。

getClientSettings(configuration: IOpenIdOptions): UserManagerSettings {
    return {
      authority: configuration.authority + '/',
      client_id: configuration.clientId,
      redirect_uri: configuration.redirectUri,
      post_logout_redirect_uri: configuration.redirectUri,
      response_type: configuration.responseType, // "id_token token",
      scope: "openid profile email " + configuration.apiResourceId,
      filterProtocolClaims: true,
      loadUserInfo: false,
      automaticSilentRenew: true,
      monitorSession: true,
      silent_redirect_uri: configuration.silentRedirectUri,
      accessTokenExpiringNotificationTime: 20, //default 60
      checkSessionInterval: 5000, //default 2000
      silentRequestTimeout: 20000, //default: 10000 
      // When CORS is disabled, token signing keys cannot be retrieved
      //  Manual the metadata and singinKeys for okta auth
      metadata: {
        // Magic happen here. Confugure to local host 
        jwks_uri: configuration.jwksUri,
        authorization_endpoint: `${configuration.authority}/v1/authorize`,
        issuer: configuration.authority
      },
    };
  }

应用设置.json

 "openId": {
    "authority": "https://dev-166545.okta.com/oauth2/xxxxxxxxxxxxxx",
    "clientId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "apiResourceId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "redirectUri": "https://localhost:44307/auth-callback",
    "silentRedirectUri": "https://localhost:44307/assets/silent-renew.html",
    "responseType": "id_token token",
    "jwksUri" : "https://localhost:44307/assets/jwks.json"
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM