Skip to content

Commit eda0756

Browse files
authored
feat: add option to show decoded auth token claims (#254)
1 parent 629bad6 commit eda0756

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

alertaclient/commands/cmd_token.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import click
22

3+
from alertaclient.auth.token import Jwt
34
from alertaclient.auth.utils import get_token
45

56

67
@click.command('token', short_help='Display current auth token')
8+
@click.option('--decode', '-D', is_flag=True, help='Decode auth token.')
79
@click.pass_obj
8-
def cli(obj):
9-
"""Display the auth token for logged in user."""
10+
def cli(obj, decode):
11+
"""Display the auth token for logged in user, with option to decode it."""
1012
client = obj['client']
11-
click.echo(get_token(client.endpoint))
13+
token = get_token(client.endpoint)
14+
if decode:
15+
jwt = Jwt()
16+
for k, v in jwt.parse(token).items():
17+
if isinstance(v, list):
18+
v = ', '.join(v)
19+
click.echo('{:20}: {}'.format(k, v))
20+
else:
21+
click.echo(token)

0 commit comments

Comments
 (0)