BookmarkSubscribeRSS Feed
rudfaden
Pyrite | Level 9

I am trying to make an api call to google maps using a HMAC-SHA1 signed key. I have to follow these steps.

 

  1. Construct the request URL without the signature, making sure to include your client parameter. Note that any non-standard characters will need to be URL-encoded:

    https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&client=clientID

    Note: All Google services require UTF-8 character encoding (which implicitly includes ASCII). If your applications operate using other character sets, make sure they construct URLs using UTF-8 and properly URL-encode them.

  2. Strip off the domain portion of the request, leaving only the path and the query:

    /maps/api/directions/json?origin=Toronto&destination=Montreal&client=clientID

  3. Retrieve your private key, which is encoded in a modified Base64 for URLs, and sign the URL above using the HMAC-SHA1 algorithm. You may need to decode this key into its original binary format. Note that in most cryptographic libraries, the resulting signature will be in binary format.

    Note: Modified Base64 for URLs replaces the + and / characters of standard Base64 with - and _ respectively, so that these Base64 signatures no longer need to be URL-encoded.

  4. Encode the resulting binary signature using the modified Base64 for URLs to convert this signature into something that can be passed within a URL.

  5. Attach this signature to the URL within a signature parameter:

    https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&client=clientID&signature=base64signature

I found this code online, which i thought would help. But it seems to give the wrong result. I have used test case from googles website. The key suppose to be chaRF2hTJKOScPr-RQCEhZbSzIE=, but the key returned is MqYEMSmWU6nGbkqbN8DBP6PQC2o=

 

%let key = %nrstr(vNIXE0xscrmjlyV-12Nj_BvUPaw=);
%let message = %sysfunc(urlencode(%nrstr(https://maps.googleapis.com/maps/api/geocode/json?address=New+York&client=clientID)));
 
proc groovy;

add sasjar="commons_codec" version="1.7.0.0_SAS_20121211183158"; *version is specific to SAS Installation and may differ from this;

submit "&key." "&message.";
 
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import org.apache.commons.codec.binary.Base64
 
def base64hmacsha1(key, message) {
    mac = Mac.getInstance("HmacSHA1")
    mac.init(new SecretKeySpec(key.getBytes(), "HmacSHA1"))
 
    sha1_bytes = mac.doFinal(message.getBytes())
 
    base64 = new Base64()
    return new String(base64.encode(sha1_bytes))
}
 
exports.base64hmacsha1 = base64hmacsha1(args[0], args[1])
 
endsubmit;
 
quit;
%put &base64hmacsha1.;
/*chaRF2hTJKOScPr-RQCEhZbSzIE=*/

 

2 REPLIES 2
ChrisHemedinger
Community Manager

Not avoiding your original question, but depending on what you're trying to do with Google Maps, this series of articles about Google Maps with SAS from @LeonidBatkhan might help.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
rudfaden
Pyrite | Level 9
I am trying to use a Google premium account for google maps, as I need to use Google maps beyond with is available free

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1299 views
  • 0 likes
  • 2 in conversation