Report this

What is the reason for this report?

Getting "missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel" when using spaces

Posted on February 4, 2018

Hi,

I’m trying to use the AWS Javascript SDK with spaces but for some reason I’m getting the following error in the Javascript console:

“missing token ‘authorization’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel”

AFAIK, this is an auth error but I thought the AWS SDK handles auth automatically.

Here is my code:

URL = "https://{$REIGON}.digitaloceanspaces.com/"

var ep = new AWS.Endpoint(URL);
var s3 = new AWS.S3({
  endpoint: ep,
  accessKeyId: "{$ACCESSKEY}",
  secretAccessKey: "{$SECRETKEY}",
});

s3.listBuckets({}, function(err, data) {
  if (err) console.log(err, err.stack);
  else console.log(dat);
});

s3.getObject(
  { Bucket: "bucket1", Key: "keyvalue" },
  function (error, data) {
    if (error != null) {
      alert("Failed to retrieve object: " + error);
    } else {
      alert("Loaded" + data.ContentLength + " bytes");
    }
  }
);


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

lease make sure to set up proper CORS rules on your DigitalOcean Space. You can accomplish this by going to the Spaces Dashboard, clicking on the “Settings” tab within your Space, and configuring the “CORS Configuration”.

Here’s an example CORS configuration that allows all origins and the required headers for the AWS SDK:

  1. [
  2. {
  3. "AllowedHeaders": [
  4. "*"
  5. ],
  6. "AllowedMethods": [
  7. "PUT",
  8. "POST",
  9. "DELETE",
  10. "GET"
  11. ],
  12. "AllowedOrigins": [
  13. "*"
  14. ],
  15. "ExposeHeaders": [
  16. "ETag",
  17. "x-amz-meta-custom-header",
  18. "Authorization",
  19. "Content-Type"
  20. ],
  21. "MaxAgeSeconds": 3000
  22. }
  23. ]

For further information, please refer to the DigitalOcean CORS documentation.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.