Acess-Control-Allow-Headers CORS-Fehler mit API nach Aktualisierung von Discourse

Ich habe Discourse gestern aktualisiert und erhalte bei allen API-Rückrufen einen Fehler. Ich habe herausgefunden, dass das Problem in den Authentifizierungs-Headern liegt (1). Bei einigen Testaufrufen erhalte ich jedoch diesen Fehler:

Zugriff auf XMLHttpRequest an 'https://mydomain.com/notifications.json?username=admin' von der Herkunft 'https://mydomain.com' wurde durch die CORS-Richtlinie blockiert: Das Anforderungs-Header-Feld api-username ist in der Preflight-Antwort von Access-Control-Allow-Headers nicht erlaubt.

Ich verwende Vue und habe den api-key und api-username wie folgt zu den Headern hinzugefügt:

Vue.http
        .get(
             "https://discourse.mydomain.com/notifications.json?username="+input.username,
          {
            headers: {
             "Api-Key":"xxxxxxxxxxxxxxxxx",
             "Api-Username": "system",
              "content-type": "application/json",
              accept: "application/json"
            }
          }
        )

(1) Discourse REST API Documentation

You may need to have CORS setup in your site settings?

Yes, I have added the domain where I call the API in discourse settings, but that error about field api-username, I dont know when I have to resolve.

You are putting your system API key in client side code? :scream:
This means that anyone can grab it from your Javascript code and use it to completely own your forum.

Any Ajax HTTP requests to Discourse should be leveraging an existing session, or not be needing a session at all.

3 „Gefällt mir“

Not just a testing , I am using the username

      Vue.http
    .get(
      "https://discourse.mydomain.com/notifications.json?username="+input.username,
      {
        headers: {
       "Api-Key":"xxxxxxxxxxxxxxxxxxxxxx",
        "Api-Username": input.username    
        }
      }
    )

But I getting the same error with de Cors and the field api-username

1 „Gefällt mir“

Let me repeat what I said:

That means: no authentication headers. At all.

1 „Gefällt mir“

You really should not be using these API credentials for CORS requests which is why that header field is not allowed.

However we do allow the user-api headers in CORS:

3 „Gefällt mir“

I have read the User API keys specification

In my case I have SSO with a frontend app in javascript, Could I consuming the API without using the authorization UI for every user? I would like a way that a could use de api-username … is that possible?

Regards

Könntest du das lösen?
Vielen Dank!

Am Ende bin ich zur vorherigen Version von Discourse zurückgekehrt, damit ich nicht alle API-Integrationen anpassen musste.