<div dir="ltr"><div>... and here is a quick helper function for your shell:</div><div><br></div><div>#Keycloak</div><div>decode_jwt(){</div><div> echo -n $@ | cut -d "." -f 2 | base64 -d | jq .</div><div>}</div><div>alias jwtd=decode_jwt</div><div><br></div><div><div>$ jwtd $KC_ACCESS_TOKEN</div><div>{</div><div> "jti": "c5ed8525-f0c6-433f-9a88-ef92645582dd",</div><div> "exp": 1473348085,</div><div> "nbf": 0,</div><div> "iat": 1473347785,</div><div> "iss": "<a href="http://localhost:8081/auth/realms/acme-test">http://localhost:8081/auth/realms/acme-test</a>",</div><div> "aud": "app1",</div><div> "sub": "c88e9053-89cf-4a4b-af09-c34d91d083af",</div><div> "typ": "Bearer",</div><div> "azp": "app1",</div><div> "auth_time": 0,</div><div> "session_state": "bfb1e6dd-b8c6-4379-bc47-e86c5396b06b",</div><div> "acr": "1",</div><div> "client_session": "db292d8b-263e-4030-9b93-a1d37e5ee5eb",</div><div> "allowed-origins": [],</div><div> "resource_access": {</div><div> "app-js-demo-client": {</div><div> "roles": [</div><div> "user"</div><div> ]</div><div> },</div><div> "account": {</div><div> "roles": [</div><div> "manage-account",</div><div> "view-profile"</div><div> ]</div><div> }</div><div> },</div><div> "name": "Theo Tester",</div><div> "preferred_username": "tester",</div><div> "given_name": "Theo",</div><div> "family_name": "Tester",</div><div> "email": "tom+tester@localhost"</div><div>}</div></div><div><br></div><div>Cheers,</div><div>Thomas</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-09-08 17:20 GMT+02:00 Thomas Darimont <span dir="ltr"><<a href="mailto:thomas.darimont@googlemail.com" target="_blank">thomas.darimont@googlemail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello group,</div><div><br></div><div>just found an interesting example for decoding a JWT token in the shell.</div><div>Perhaps some of you might find that handy... see below.</div><div><br></div><div>Cheers,</div><div>Thomas</div><div><br></div><div>KC_REALM=acme-test</div><div>KC_USERNAME=tester</div><div>KC_PASSWORD=test</div><div>KC_CLIENT=app1</div><div>KC_CLIENT_SECRET=aa937217-<wbr>a566-49e4-b46e-97866bad8032</div><div>KC_URL="<a href="http://localhost:8081/auth" target="_blank">http://localhost:8081/<wbr>auth</a>"</div><div><br></div><div># Request Tokens for credentials</div><div>KC_RESPONSE=$( \</div><div> curl -k -v \</div><div> -d "username=$KC_USERNAME" \</div><div> -d "password=$KC_PASSWORD" \</div><div> -d 'grant_type=password' \</div><div> -d "client_id=$KC_CLIENT" \</div><div> -d "client_secret=$KC_CLIENT_<wbr>SECRET" \</div><div> "$KC_URL/realms/$KC_REALM/<wbr>protocol/openid-connect/token" \</div><div> | jq . </div><div>)</div><div><br></div><div>KC_ACCESS_TOKEN=$(echo $KC_RESPONSE| jq -r .access_token)</div><div>KC_ID_TOKEN=$(echo $KC_RESPONSE| jq -r .id_token)</div><div>KC_REFRESH_TOKEN=$(echo $KC_RESPONSE| jq -r .refresh_token)</div><div><br></div><div># one-liner to decode access token</div><div>echo -n $KC_ACCESS_TOKEN | cut -d "." -f 2 | base64 -d | jq .</div><div><br></div><div>{</div><div> "jti": "c5ed8525-f0c6-433f-9a88-<wbr>ef92645582dd",</div><div> "exp": 1473348085,</div><div> "nbf": 0,</div><div> "iat": 1473347785,</div><div> "iss": "<a href="http://localhost:8081/auth/realms/acme-test" target="_blank">http://localhost:8081/auth/<wbr>realms/acme-test</a>",</div><div> "aud": "app1",</div><div> "sub": "c88e9053-89cf-4a4b-af09-<wbr>c34d91d083af",</div><div> "typ": "Bearer",</div><div> "azp": "app1",</div><div> "auth_time": 0,</div><div> "session_state": "bfb1e6dd-b8c6-4379-bc47-<wbr>e86c5396b06b",</div><div> "acr": "1",</div><div> "client_session": "db292d8b-263e-4030-9b93-<wbr>a1d37e5ee5eb",</div><div> "allowed-origins": [],</div><div> "resource_access": {</div><div> "app-js-demo-client": {</div><div> "roles": [</div><div> "user"</div><div> ]</div><div> },</div><div> "account": {</div><div> "roles": [</div><div> "manage-account",</div><div> "view-profile"</div><div> ]</div><div> }</div><div> },</div><div> "name": "Theo Tester",</div><div> "preferred_username": "tester",</div><div> "given_name": "Theo",</div><div> "family_name": "Tester",</div><div> "email": "tom+tester@localhost"</div><div>}</div><div><br></div></div>
</blockquote></div><br></div>