This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,618 additions
and
570 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const BbPromise = require('bluebird'), | ||
azure = require('azure-storage'), | ||
Querystring = require('querystring'), | ||
Operations = require('./../../core/Constants').Operations; | ||
|
||
const _blobService = azure.createBlobService("UseDevelopmentStorage=true;"); | ||
|
||
module.exports = (req, res) => { | ||
BbPromise.try(() => { | ||
const request = req.azuriteRequest; | ||
if (request.query.sig) { | ||
const sharedAccessPolicy = { | ||
AccessPolicy: { | ||
Permissions: request.query.sp, | ||
Start: request.query.st, | ||
Expiry: request.query.se, | ||
IPAddressOrRange: request.query.sip, | ||
Protocols: request.query.spr, | ||
Services: request.query.ss, | ||
ResourceTypes: request.query.sr, | ||
Version: request.query.sv, | ||
Id: request.query.si | ||
} | ||
}; | ||
request.auth = {}; | ||
request.auth.sasValid = checkServiceSignature(request.query, request.containerName, request.blobName, sharedAccessPolicy); | ||
request.auth.accessPolicy = sharedAccessPolicy.AccessPolicy; | ||
} | ||
next(); | ||
}).catch((e) => { | ||
res.status(e.statusCode || 500).send(e.message); | ||
if (!e.statusCode) throw e; | ||
}); | ||
} | ||
|
||
function checkServiceSignature(query, containerName, blobName, sharedAccessPolicy) { | ||
const sas = _blobService.generateSharedAccessSignature(containerName, blobName, sharedAccessPolicy), | ||
signature = Querystring.parse(sas).sig; | ||
return signature === query.sig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.