簡體   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