Re: Getting data from Google Analytics within a Magic program XPA 3.3g


Graham White
 

Hi Friedrich,

My initial problem is obtaining a token from Google for a service account.  I have to create a JWT Base64url encoded.  Below is the example they give at Using OAuth 2.0 for Server to Server Applications  |  Google Identity  

This is what it says at that link above

The signing algorithm in the JWT header must be used when computing the signature. The only signing algorithm supported by the Google OAuth 2.0 Authorization Server is RSA using SHA-256 hashing algorithm. This is expressed as RS256 in the alg field in the JWT header.

Sign the UTF-8 representation of the input using SHA256withRSA (also known as RSASSA-PKCS1-V1_5-SIGN with the SHA-256 hash function) with the private key obtained from the Google API Console. The output will be a byte array.

Below is an example of a JWT before Base64url encoding:
{"alg":"RS256","typ":"JWT"}.
{
"iss":"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@...",
"scope":"https://www.googleapis.com/auth/prediction",
"aud":"https://oauth2.googleapis.com/token",
"exp":1328554385,
"iat":1328550785
}.
[signature bytes]

Based on that I have created 

{"alg":"RS256","typ":"JWT"}.
{
"iss":"EMAIL ADDRESS WE GOT",
"scope":"https://www.googleapis.com/auth/analytics.readonly",
"aud":"https://oauth2.googleapis.com/token",
"exp":1622108446,
"iat":1622104846
}.
{"OUR PRIVATE KEY"}

I then base64url encode it and use that in curl to get a token.  No matter what I do I always get

"error": "invalid_request",
  "error_description": "Bad Request"

I am a bit of a loss to figure out why.

I am unsure of exactly this means "Sign the UTF-8 representation of the input using SHA256withRSA (also known as RSASSA-PKCS1-V1_5-SIGN with the SHA-256 hash function) with the private key obtained from the Google API Console. The output will be a byte array."

Do I need to do something with the private key we received when registering the service account?  What am i missing?

I hope you or someone can help.

Regards
Graham White


Join main@magicu-l.groups.io to automatically receive all group messages.