question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

generateSharedAccessSignature returning date in wrong format

See original GitHub issue

Which service(blob, file, queue, table) does this issue concern?

blob

Which version of the SDK was used?

2.10.2

What’s the Node.js/Browser version?

8.11.1

What problem was encountered?

generateSharedAccessSignature when used returning 403 make sure header is formatted correctly

Steps to reproduce the issue?

I have this code:

var azure = require('azure-storage');

module.exports = function(context, req) {
  if (req.body.container) {
    // The following values can be used for permissions:
    // "a" (Add), "r" (Read), "w" (Write), "d" (Delete), "l" (List)
    // Concatenate multiple permissions, such as "rwa" = Read, Write, Add
    context.res = generateSasToken(
      context,
      req.body.container,
      req.body.blobName,
      req.body.permissions
    );
  } else {
    context.res = {
      status: 400,
      body: "Specify a value for 'container'"
    };
  }

  context.done(null, context);
};

function generateSasToken(context, container, blobName, permissions) {
  var connString = process.env.AzureWebJobsStorage;
  var blobService = azure.createBlobService(connString);

  // Create a SAS token that expires in an hour
  // Set start time to five minutes ago to avoid clock skew.
  var startDate = new Date();
  startDate.setMinutes(startDate.getMinutes() - 5);
  var expiryDate = new Date(startDate);
  expiryDate.setMinutes(startDate.getMinutes() + 60);

  permissions = permissions || azure.BlobUtilities.SharedAccessPermissions.READ + azure.BlobUtilities.SharedAccessPermissions.WRITE;

  var sharedAccessPolicy = {
    AccessPolicy: {
      Permissions: permissions,
      Start: startDate,
      Expiry: expiryDate
    }
  };

  var sasToken = blobService.generateSharedAccessSignature(
    container,
    blobName,
    sharedAccessPolicy
  );

  context.log(sasToken);

  return {
    token: sasToken,
    uri: blobService.getUrl(container, blobName, sasToken, true)
  };
}

BUt the date in the return token looks different if I go into the portal and create a token:

Portal token looks like this:

?sv=2018-03-28&ss=b&srt=sco&sp=rwdlac&se=2019-01-30T23:19:06Z&st=2019-01-30T15:19:06Z&spr=https&sig=xxxxxxx

response returned from generateSharedAccessSignature

st=2019-01-30T16%3A19%3A12Z&se=2019-01-30T17%3A19%3A12Z&sp=racw&sv=2018-03-28&sr=c&sig=AhtXpqFfhCnUjwcN5SBcA2hAZw0P35S32QeoTLeEWvQ%3D

The dates look different and the sig looks completely different also.

Have you found a mitigation/solution?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Prussiacommented, Apr 10, 2020

Hey, man. What is the resolution? I have a similar issue.

1reaction
dagda1commented, Jan 31, 2019

i’m sorry that does not make a lot of sense to me. all i want to do is returns a sas token to my website users can upload files. my permissions are in the right order but i get the 403. can you please help how to do this. i don’t understand what i have to do and i can’t find any useful information. i’m coming from aws where everything just works to azure which is horrific. lots of out of date docs and code and no real pointers how to do anything. it is really depressing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node azure blobService.generateSharedAccessSignature ...
Node azure blobService.generateSharedAccessSignature() returns an incorrect token · Can you share the shared access signature returned? Also what ...
Read more >
How to correct a #VALUE! error in the DATEVALUE function
When Excel finds an incompatibility between the format in the date_text argument and the system's Date and Time settings, you will see a...
Read more >
How to change Excel date format and create custom formatting
The first part of our tutorial focuses of formatting dates in Excel and explains how to set the default date and time formats,...
Read more >
Problem with American date format when using selectedvalue ...
The table is set to dd/mm/yyyy format Dates = CALENDAR(TODAY()+1, ... Title Date = var selecteddate = SELECTEDVALUE(Dates[Date]) return ...
Read more >
Date and time - The Modern JavaScript Tutorial
Create a Date object with the time equal to number of ... That may lead to wrong results. ... If the format is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found