API auth over http


#1

We are trying to pull in Issues into a dashboard but I cannot get requests to the api to auth, i keep getting:

{"detail": "Authentication credentials were not provided."}

We are using axios like so:

const config = {
    headers: {
        Authorization: `Bearer ${token}`
    }
}

axios.get(url, config)
        .then(response => this.onDataFetchSuccess(response.data))

The initial OPTIONS request returns 401 unauthorized with the above error.

Chrome network tab shows this in Request Headers


Provisional headers are shown
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: GET
Origin: http://localhost:6060
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36

Making a curl request as in the docs works fine:

curl -H 'Authorization: Bearer {token}' https://sentry.io/api/0/projects/

Any help is appreciated


#2

Hi,

Sentry currently doesn’t support CORS requests on its APIs. I’d recommend one of the following:

  • sending those requests from your backend, or making a simple serverside app that makes those requests on behalf of your JS frontend.
  • putting something in your nginx config that intercepts those options requests before they hit sentry and returns a correct Access-Control-Allow-Origin header.

#3

Getting the same errors, spent the whole day reading the docs and trying to figure out why. Would have been ideal if these kind of info are stated in the API docs.