Hi Jason,
This is me creating a JWT token for Twilio's Chat API system.
CreateTwilioToken PROCEDURE (STRING lAccountSID,STRING lAPIKey,STRING lAPISecret,STRING lServiceSID,STRING lPushSID,STRING lIdentity)
stHeader StringTheory
stPayload StringTheory
stToEncrypt StringTheory
stSignature StringTheory
Crypto Cryptonite
CODE
stHeader.SetValue('{{"typ":"JWT","alg":"HS256","cty":"twilio-fpa;v=1"}')
stPayload.SetValue('{{"jti":"'&CLIP(lAPIKey)&'-'&RANDOM(100000000,999999999)&'",'&|
'"iss":"'&CLIP(lAPIKey)&'",'&|
'"sub":"'&CLIP(lAccountSID)&'",'&|
'"iat":'&TimestampZ()-(GETINI('Server','Timezone',0,GLO:INIFilename)*3600)&','&|
'"exp":'&TimestampZ()+3600-(GETINI('Server','Timezone',0,GLO:INIFilename)*3600)&','&|
'"grants":{{'&|
'"identity":"'&CLIP(lIdentity)&'",'&|
'"chat":{{'&|
'"service_sid":"'&CLIP(lServiceSID)&'",'&|
'"push_credential_sid":"'&CLIP(lPushSID)&'"'&|
'}}}')
stHeader.Base64Encode(1)
stHeader.Replace('+','-')
stHeader.Replace('/','_')
stHeader.Replace('=','')
stPayload.Base64Encode(1)
stPayload.Replace('+','-')
stPayload.Replace('/','_')
stPayload.Replace('=','')
stToEncrypt.SetValue(stHeader.GetValue()&'.'&stPayload.GetValue())
Crypto.MakeHMAC(stToEncrypt,CLIP(lAPISecret),cs:CALG_SHA_256,0)
stToEncrypt.Base64Encode(1)
stToEncrypt.Replace('+','-')
stToEncrypt.Replace('/','_')
stToEncrypt.Replace('=','')
RETURN stHeader.GetValue()&'.'&stPayload.GetValue()&'.'&stToEncrypt.GetValue()
I'm in a hurry tonight getting a build out. But, if you want the exact code, ask me on Slack.
Regards
Bill