From e25400d251b4345dd5ff0c22c278addf79cda327 Mon Sep 17 00:00:00 2001 From: Nick Satterly Date: Sat, 17 Apr 2021 23:23:04 +0200 Subject: [PATCH] feat: add option to show decoded auth token claims --- alertaclient/commands/cmd_token.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/alertaclient/commands/cmd_token.py b/alertaclient/commands/cmd_token.py index a99e651..a66cf55 100644 --- a/alertaclient/commands/cmd_token.py +++ b/alertaclient/commands/cmd_token.py @@ -1,11 +1,21 @@ import click +from alertaclient.auth.token import Jwt from alertaclient.auth.utils import get_token @click.command('token', short_help='Display current auth token') +@click.option('--decode', '-D', is_flag=True, help='Decode auth token.') @click.pass_obj -def cli(obj): - """Display the auth token for logged in user.""" +def cli(obj, decode): + """Display the auth token for logged in user, with option to decode it.""" client = obj['client'] - click.echo(get_token(client.endpoint)) + token = get_token(client.endpoint) + if decode: + jwt = Jwt() + for k, v in jwt.parse(token).items(): + if isinstance(v, list): + v = ', '.join(v) + click.echo('{:20}: {}'.format(k, v)) + else: + click.echo(token)