Created
July 4, 2014 04:57
-
-
Save andreabadesso/82cc4584c9d07aebcf71 to your computer and use it in GitHub Desktop.
Sign Google Maps for Business requests with the privateKey using Node.js
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
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