2016-08-19 84 views
0

我已经创建了谷歌服务帐户,并有包含private_keyclient_email使用erlang计算Google OAuth服务帐户的JWT签名?

JWT should be createdget 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智威汤逊签名?

回答

1

有些图书馆已经建立了这样做。其中一个(我正在使用)是Erlang JOSE

%% In OTP 17 or later 
Signed = jose_jwt:sign(RSAPrivate, #{ <<"alg">> => <<"RS256">> }, Payload), 
{_JWS, Token} = jose_jws:compact(Signed). 
相关问题