Bash OAuth 2.0 Script JWT para Servidor para Aplicativos do Servidor do Google

5

Estou tentando criar um script jwt que me ofereça tokens com base no link Isso é o que eu tenho até agora, mas o servidor de token responde que grant_type é inválido?

jwt1='echo -n '{"alg":"RS256","typ":"JWT"}' | base64'

jwt2='echo -n '{\
"iss":"[email protected]",\
"scope":"https://www.googleapis.com/auth/datastore",\
"aud":"https://accounts.google.com/o/oauth2/token",\
"exp":'$(($(date +%s)+3600))',\
"iat":'$(date +%s)'}' | base64'

jwt3='echo -n "$jwt1.$jwt2" | tr -d '\n' | sed 's/==//g''

jwt4='echo -n "$jwt3" | openssl sha -sha256 -sign google.p12 | base64'

jwt5='echo -n "$jwt4" | tr -d '\n' | sed 's/=//g''

curl -H "Content-type: application/x-www-form-urlencoded" -X POST "https://accounts.google.com/o/oauth2/token" -d \
"grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=$jwt3.$jwt5"
    
por Gert Cuykens 13.06.2013 / 03:57

1 resposta

7
jwt1='echo -n '{"alg":"RS256","typ":"JWT"}' | openssl base64 -e'

jwt2='echo -n '{\
"iss":"[email protected]",\
"scope":"https://www.googleapis.com/auth/datastore",\
"aud":"https://accounts.google.com/o/oauth2/token",\
"exp":'$(($(date +%s)+3600))',\
"iat":'$(date +%s)'}' | openssl base64 -e'

jwt3='echo -n "$jwt1.$jwt2" | tr -d '\n' | tr -d '=' | tr '/+' '_-''

jwt4='echo -n "$jwt3" | openssl sha -sha256 -sign google.p12 | openssl base64 -e'

jwt5='echo -n "$jwt4" | tr -d '\n' | tr -d '=' | tr '/+' '_-''

curl -H "Content-type: application/x-www-form-urlencoded" -X POST "https://accounts.google.com/o/oauth2/token" -d \
"grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=$jwt3.$jwt5"
    
por 13.06.2013 / 18:16