generate_jwt
The generate_jwt
statement is used to generate an RFC 7515-compliant JWT (JSON Web Token) which can be used, for example, for Google Cloud OAuth 2.0 Server to Server Authentication.
Syntax
generate_jwt key
key component1 [... componentN]
as
result
Details
The generate_jwt
statement performs the following actions:
encodes all components as Base64URL
concatenates all components using a dot separator (
.
)hashes the concatenated result using SHA256
signs the hash with a provided PEM-encoded key using the RSA algorithm
encodes the resulting signature as Base64URL
builds JWT by concatenating the two results using a dot separator (
.
)stores the final result in th variable specified by the
result
parameter
The RSA key needs to be in PEM format. PEM format requires the header and footer to be on separate lines so it is important to separate the key contents with ${NEWLINE}
as shown below:
var key = "-----BEGIN PRIVATE KEY-----${NEWLINE}Key-data-goes-here{$NEWLINE}-----END PRIVATE KEY-----"
Example
To acquire a Google Cloud OAuth 2.0 access token:
Last updated