使用erlang计算Google OAuth服务帐户的JWT签名?
问题描述:
我已经创建了谷歌服务帐户,并有包含private_key
,client_email
等使用erlang计算Google OAuth服务帐户的JWT签名?
JWT should be created到get access token JSON文件。
我按照以下步骤
头计算:
Header = jsx:encode(#{<<"alg">> => <<"RS256">>,<<"typ">> => <<"JWT">>}).
Base64Header = base64:encode(Header).
索赔计算:
Claims = jsx:encode(#{
<<"iss">> => <<"[email protected]">>,
<<"scope">> => <<"https://www.googleapis.com/auth/cloud-platform">>,
<<"aud">> => <<"https://www.googleapis.com/oauth2/v4/token">>,
<<"exp">> => 1471629262,
<<"iat">> => 1471627282
}).
Base64Claims = base64:encode(Claims).
Input = {Base64Header}.{Base64Claim}
而且, 我们如何注册使用SHA256withRSA的Input
的UTF-8表示(也称为具有SHA-256散列函数的RSASSA-PKCS1-V1_5-SIGN)与private_key
计算机te智威汤逊签名?
答
有些图书馆已经建立了这样做。其中一个(我正在使用)是Erlang JOSE。
%% In OTP 17 or later
Signed = jose_jwt:sign(RSAPrivate, #{ <<"alg">> => <<"RS256">> }, Payload),
{_JWS, Token} = jose_jws:compact(Signed).