Client and signature not implemented correctly
- Dominant language
- R
- Stars
- 778
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
Hi, we're an agency that has the Google Maps API premium that requires a client ID and signature for *each* unique API request. Right now the register_google function assumes there is a single signature that can be used on all API requests.
The details on how API URL signing is here:
https://developers.google.com/maps/documentation/maps-static/get-api-key#generating_valid_signatures
What needs to be done, I think, is that the register_google function should store not a "signature" but the secret signing key associated with the client ID, then this secret key is used to generate a signature for each static map request.
I am a very beginner R programmer, so please forgive me if this code is primitive, but I have been able to generate a valid signature value that matches what's on the Google page referenced above. Is there a way that ggmap could be altered so this signature is generated for each API request that requires a signature (static map, geocode, maybe others referenced by ggmap)?
Thanks, Tim
```
install.packages("digest")
install.packages("base64enc")
library(digest)
library(base64enc)
#url must be encoded
inputURL <- 'https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&client='
#locating the third slash in the URL (start of path), no doubt a more elegant way to do this
slashes = gregexpr(pattern="/",inputURL)
urlToSign = substr(inputURL,slashes[[1]][3],9999)
textKey <- ''
#translate key to un-websafe
safeKey <- sub("-","+",textKey,fixed=TRUE)
safeKey <- sub("_","/",safeKey,fixed=TRUE)
binKey <- base64decode(safeKey)
urlSig <- hmac(binKey,urlToSign,"sha1",FALSE,TRUE)
encSig <- base64encode(urlSig)
#signature to web safe
safeSig <- sub("+","-",encSig,fixed=TRUE)
safeSig <- sub("/","_",safeSig,fixed=TRUE)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.