Skip to content

Instantly share code, notes, and snippets.

@andreabadesso
Created July 4, 2014 04:57
Show Gist options
  • Save andreabadesso/82cc4584c9d07aebcf71 to your computer and use it in GitHub Desktop.
Save andreabadesso/82cc4584c9d07aebcf71 to your computer and use it in GitHub Desktop.
Sign Google Maps for Business requests with the privateKey using Node.js
var crypto = require('crypto'),
url = require('url'),
URLSafeBase64 = require('urlsafe-base64');
function GenerateSignature(privateKey, query) {
var u = url.parse(query);
var urlToSign = u.path;
var decodedKey = URLSafeBase64.decode(privateKey);
var signature = crypto.createHmac('sha1', decodedKey).update(urlToSign);
var encodedSignature = URLSafeBase64.encode(signature.digest());
return "http://maps.googleapis.com" + u.pathname + "?" + u.query + "&signature=" + encodedSignature;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment