Support creating signed urls for Cloud CDN #2437
Copy link
Copy link
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.samplesIssues that are directly related to samples.Issues that are directly related to samples.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
Activity
- addedsamplesIssues that are directly related to samples.Issues that are directly related to samples.
on Nov 19, 2021 - addedpriority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
on Nov 19, 2021 I was going through Cloud CDN documentation to find how to programmatically generate signed CDN urls and nodejs example was really missing for me. After several hours of trial and error I managed to came up with a solution. I opened a PR adding corresponding nodejs code snippet #4011.
Not sure what is the process of updating above mentioned docs to add this snippet though.
For anybody searching online for a quick copy-paste, here is the whole snippet:
const crypto = require('crypto'); /** * Sign url to access Google Cloud CDN resource secured by key. * @param url the Cloud CDN endpoint to sign * @param keyName name of the signing key configured in the backend service/bucket * @param keyValue value of the signing key * @param expirationDate the date that the signed URL expires * @return signed CDN URL */ function signUrl(url, keyName, keyValue, expirationDate) { const urlObject = new URL(url); urlObject.searchParams.set( 'Expires', Math.floor(expirationDate.valueOf() / 1000).toString() ); urlObject.searchParams.set('KeyName', keyName); const signature = crypto .createHmac('sha1', Buffer.from(keyValue, 'base64')) .update(urlObject.href) .digest('base64url'); urlObject.searchParams.set('Signature', signature); return urlObject.href; }
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.samplesIssues that are directly related to samples.Issues that are directly related to samples.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Originally filed in nodejs-storage by @TriPSs
This is a request for a Node.js sample on this page
Is your feature request related to a problem? Please describe.
We want to implement signed urls that go through the load balancer with Cloud CDN, this library does not yet expose a method that can be used to generate those urls.
Describe the solution you'd like
An method that will generate these urls for us.
Describe alternatives you've considered
Create the custom code inside the application itself.
Additional context
Would be awesome if this could be integrated inside the library as now everyone who needs this needs to figure it out themselves (As the Google Cloud docs does not have an example for node) and create their own solution.
Outstanding question: