Expected behaviour and actual result.
I expect the server to return all allow-headers needed for the various types of auth and auth tokens that are supported.
The current list does not include X-Dgraph-AuthToken
which is referenced here in the securing alter operations section.
this is what Chrome shows in the network pane:
access-control-allow-headers: X-Dgraph-AccessToken, Content-Type,
Content-Length, Accept-Encoding, Cache-Control,
X-CSRF-Token, X-Auth-Token, X-Requested-With
This means i can succeed to send the auth token using the dgraph-js-http client on node.js (because there are no preflight checks), but the browser rejects the request if i use the designated function in dgraph-js-http:
newClientStub.setAlphaAuthToken("<someSortofR4ndomKey-F00D1ddlyDee>")
with the following error:
Access to fetch at 'https://my.dghttp.url/query?timeout=600s' from origin 'http://localhost:8080' has been blocked by CORS policy: Request header field x-dgraph-authtoken is not allowed by Access-Control-Allow-Headers in preflight response.
I was able to use the dgraph-js-http client from node successfully to do a DQL alter operation.
Now when I try to set up a GraphQL schema using curl i get strange results:
><> curl --data-binary '@schema.graphql' -X POST 'https://my.dghttp.url/admin/schema'
{"errors":[{"message":"Invalid X-Dgraph-AuthToken","extensions":{"code":"ErrorUnauthorized"}}]}⏎
><> curl -H 'X-Dgraph-AuthToken: totallywrongkey' --data-binary '@schema.graphql' -X POST 'https://my.dghttp.url/admin/schema'
{"errors":[{"message":"Invalid X-Dgraph-AuthToken","extensions":{"code":"ErrorUnauthorized"}}]}⏎
><> curl -H 'X-Dgraph-AuthToken: <correctKey>' --data-binary '@schema.graphql' -X POST 'https://my.dghttp.url/admin/schema'
{"errors":[{"message":"resolving updateGQLSchema failed because No Auth Token found. Token needed for Alter operations. (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}⏎
When sending the totallywrong key and no key at all i get the same ErrorUnauthorized (so far, so good)… When sending the correct key i get the third error - which is different, so it indicates that it got to a different section of internal code, but still not allowing the alter operation…
For the first part i suggest adding the X-Dgraph-AuthToken to the servers ( although i’ve never written a line of go in my life i guess it is somewhere around here )
For the second part, i am open to suggestions, maybe its the simple need for an additional header or some sort of quotes escaping… ??