Skip to content

Instantly share code, notes, and snippets.

@marcgreenstock marcgreenstock/mbaasy_jwt.rb Secret
Last active Nov 3, 2018

Embed
What would you like to do?
require 'jwt'
SERVICE_ACCOUNT_ID = '43a7584f-317a-4d28-a962-11db90887392'
PRIVATE_KEY = <<~PEM
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAq3ow03GNc+GRgY9ruDBKGOTx67jlNv4o8Kp8RD5gWj8yID1B
+sozze09x9ov8ZQvp9i3GDtkx91/TaKW5UG1NiHh6Chg9jUXJpgLOLCnt+J3UP/L
c/XK36U6ujR21fEy+fysF2EjmHEUaHxAdR4Rf9aQxuNL9iWLI0l1jeT9fLR4/aGl
BF4S3CS2xcuJG/Gf/oaPwOhVBhtwp1vlJVAwmgZ+OJJ6d9pxPxI9ovsVBkP95SvN
6QHWWOjQADHPRdLaEzW4Cn6qrb9tA1RXkOPnPDzhBCL4C+1Vj/G0Ma+GUzJyogIN
kKd2u6pMAyg4SKPwMpSNFIncgoY3oDO1YH3SnQIDAQABAoIBAQCR6VmesmMhFfHQ
gw+wHTcP09CfOiehEcgYcZloIIOwh1HJ6RY5ptFKCvOlGV3ufJ/IfTnfXrq07x8i
GpW34p+lvlMSTzmihy554qq5xGgSqpvIysB+ncnRYDGGvJnaFnHAEmcFRd0aHC63
cfMPNVTCqPtsoYDDpNKuZhWndhDUiQBDVWrKtbDnWSs9q43c5n5hfOgfdXJUpi/z
Jm5SHWVXRbh9RrlJE8T00zB093mLLqdEWjnZ+6S1TaohSLYW4Ea4Z6vevLFoGfS3
xjJx5ewtr8RTmo9Rkfc5ms7xT5t7ATzYQ/JttyZ/8BORHNreEShzVK4qK30gVbSb
7r86PBtpAoGBANVCKwDCVqKbUQ7JYJaym128O67WTdtHuKoGYSbvQbF2G9SRq0Zy
6kH9hZsY0MLWTH7whn9/Z857Oan7MZLR9r5nX4Sm0vXHhR/gGoCKRSPr167kpFp7
OktUN75k18VqJpyLRd3PVp0QgP1gSkNUFwL6ibLnwhFWDOkpW7iuzpmrAoGBAM3Y
Uk1BjwBBg9muG4NczY3Bl+krLUse+qYfBHyZgkiVGQ53ZNh7wbo6vtKhVsrjzsG8
OGN2zn0ylyRokUGkUQ0Y9oIZG4F2ZOqyoeYejc4MdrROc9Uexduali2tMU218w6O
O/e0kKZLb2+Ek4P+leA+XPGhCN+Vmq0IUF2uFEzXAoGBAIJhxfDc4CLiWphzvj3k
TODuKH8oPsmF+/zXkaZAOSXKVBGOTezwbRCTc4/ziA7W/kXNwC1LM6gl5odqMFDX
VcfrY5ayd+AUb+uhFBLqdoMTufYPi/xVwrozbzFUbicgUyL6c2i9TvMQGAzRRhYL
31XO30kmMJxww8v5oT40gdOpAoGAd0aM0hVV3mkYFI+Ng73Hogd2lfad5TSLOq0o
dWaiFprGjRpjxglYBSg7IGO6nhAI4zvEVOYn2mXxLHinCqlDCdrYJCSWSpsm+NQP
ef9kXevc8Lew6OJO9eQKd2cu9X+j2mBSoULwultls/HXZJmlkO2x/5U3Rg8zNGZn
4xCW1LsCgYEAwFXgAZThUG+Hl4AZj+hUu/gL8dYOYid7WE5O6PDThQ0MPwV3Raoc
udtd/vWUO5+IWs6FqXCXpiJ6+jplUGOfrAlSSe2epjm1BJvqSPiPEN2hWVt5Gruq
W+1Fw7AJTm7YQoQZ+HjnJxlq6dcmXtE3DuDVrlWXNutVjOGksTblgmY=
-----END RSA PRIVATE KEY-----
PEM
now = Time.now
payload = {
aud: 'ServiceAccount',
sub: SERVICE_ACCOUNT_ID,
iat: now,
nbf: now,
exp: now.to_i + (60 * 60)
}
private_key = OpenSSL::PKey::RSA.new(PRIVATE_KEY)
token = JWT.encode(payload, private_key, 'RS256')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.