2016-08-19 2 views
0

내가 구글 서비스 계정을 생성하고erlang을 사용하여 Google OAuth 서비스 계정에 대한 JWT 서명을 계산 하시겠습니까?

JWT should be createdget access tokenprivate_key, client_email 등이 포함 된 JSON 파일이 있습니다.

I 단계

다음 따랐다

헤더 계산 :

Header = jsx:encode(#{<<"alg">> => <<"RS256">>,<<"typ">> => <<"JWT">>}). 
Base64Header = base64:encode(Header). 

주장 계산 : 우리가 SHA256withRSA를 사용하여 Input의 UTF-8 표현을 가입 할 수 있습니다 방법

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} 

그리고, (SHA-256 해시 기능을 사용하는 RSASSA-PKCS1-V1_5-SIGN이라고도 함)에 private_key을 입력하고 JWT 서명?

답변

1

이미이를 위해 만들어진 라이브러리가 있습니다. 하나는 (내가 사용하고있는) Erlang JOSE입니다.

%% In OTP 17 or later 
Signed = jose_jwt:sign(RSAPrivate, #{ <<"alg">> => <<"RS256">> }, Payload), 
{_JWS, Token} = jose_jws:compact(Signed). 
관련 문제