Jump to content

JSON Web Signature and byte arrays


Recommended Posts

So I have been reading on how to use OAuth2 Service accounts(https://developers.google.com/identity/protocols/OAuth2ServiceAccount) and ran into an issue with autoit I can not solve. To keep this short to communicate to the Google API I need to use a JSON Web signature containing

{Base64url encoded header}.{Base64url encoded claim set}.

2019-06-04_1450.png.28afd03341f6a64ef36f0c19c221d9f3.png

The Header and claim set work fine but I do not know how to convert them to a byte array using autoit. I have looked around on the forums and website but have not found anything that seems to work. Here is my code.

#include-once
#include <Array.au3>
#include <Constants.au3>
#include <Debug.au3>
#include <File.au3>
#include "Json.au3"
#include <Process.au3>
#include <ProgressConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include "WinHttp.au3"
#include <UnixTime.au3>
#include <StringConstants.au3>

Global $UnixTime = _TimeGetStamp()
$sJWTheader = '{"alg":"RS256","typ":"JWT"}'
$sJWTclaimset = '{"iss":"Removed@forprivacy.com","scope":"https://www.googleapis.com/auth/spreadsheets","aud":"https://www.googleapis.com/oauth2/v4/token","exp":' & $UnixTime + 3600 & ',"iat":' & $UnixTime & '}'



Local $taiData = DllStructCreate("BYTE[256]")
Local $sText = _base64($sJWTheader)&'.'&_base64($sJWTclaimset)
DllStructSetData($taiData, 1, StringToBinary($sText, 4))
Local $bvResult = DllStructGetData($taiData, 1) 
$sJWTSigature = $bvResult
$sJWT = _base64($sJWTheader)&'.'&_base64($sJWTclaimset)&'.'&_base64($sJWTSigature)

$POSTHeader = "Content-Type: application/x-www-form-urlencoded"
$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "https://www.googleapis.com/")

$sRead = _WinHttpSimpleSSLRequest($hConnect, "POST", "oauth2/v4/token", Default, "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=" & $sJWT)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
ConsoleWrite($sRead & @LF)

The whole bytes thing is beyond with what I know about auotit. I can't tell what I need to fix.

 

 

No problem can withstand the assault of sustained thinking.Voltaire

_Array2HTMLTable()_IEClassNameGetCollection()_IEquerySelectorAll()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...