66
77usage ()
88{
9- echo ' Usage: htdecodetoken [-a] [-H] [-s|-f] [file]'
9+ echo ' Usage: htdecodetoken [-a] [-H] [-s|-f] [-v] [ file]'
1010 echo
1111 echo ' Decodes a JSON Web Token'
1212 echo ' -a: show algorithm portion of JWT'
@@ -15,6 +15,7 @@ usage()
1515 echo ' This is the default if stdout is not a TTY, or if scitokens-verify'
1616 echo ' is not available in the PATH.'
1717 echo ' -f: force scitokens-verify validation (cannot be used with -s)'
18+ echo ' -v: enable verbose mode, showing in stderr where token came from'
1819 echo ' File name may be "-" to read from stdin.'
1920 echo ' If file name not given, follows WLCG Bearer Token Discovery'
2021 echo ' which is to first try $BEARER_TOKEN, next $BEARER_TOKEN_FILE,'
@@ -44,7 +45,6 @@ decode_jwt() {
4445
4546
4647human_dates () {
47-
4848 local wrd
4949 local w1
5050 local date
@@ -77,12 +77,13 @@ if [ ! -t 1 ]; then
7777 SKIPVERIFY=true
7878fi
7979
80+ VERBOSE=false
8081SHOWALG=false
8182HUMANDATE=false
8283SKIPVERIFYFLAGSET=false
8384FORCEVERIFYFLAGSET=false
8485NUMSHIFT=0
85- while getopts " :aHsf " opt; do
86+ while getopts " :vaHsf " opt; do
8687 case " $opt " in
8788 a)
8889 SHOWALG=true
@@ -110,6 +111,10 @@ while getopts ":aHsf" opt; do
110111 FORCEVERIFYFLAGSET=true
111112 (( NUMSHIFT+= 1 ))
112113 ;;
114+ v)
115+ VERBOSE=true
116+ (( NUMSHIFT+= 1 ))
117+ ;;
113118 * )
114119 usage
115120 esac
@@ -121,12 +126,18 @@ TOKENFILE=""
121126if [ $# = 0 ]; then
122127 if [ -n " $BEARER_TOKEN " ]; then
123128 TOKEN=" $BEARER_TOKEN "
129+ if $VERBOSE ; then
130+ echo ' Token source: $BEARER_TOKEN' >&2
131+ fi
124132 else
125133 TOKENFILE=" ${BEARER_TOKEN_FILE:- ${XDG_RUNTIME_DIR:-/ tmp} / bt_u`id -u`} "
126134 fi
127135elif [ $# = 1 ]; then
128136 if [ " $1 " = - ]; then
129137 read TOKEN # from stdin
138+ if $VERBOSE ; then
139+ echo ' Token source: stdin' >&2
140+ fi
130141 else
131142 TOKENFILE=" $1 "
132143 fi
@@ -140,6 +151,9 @@ if [ -n "$TOKENFILE" ]; then
140151 fi
141152 # the -n is needed here for when there is no ending newline in the file
142153 read TOKEN < $TOKENFILE || [ -n " $TOKEN " ]
154+ if $VERBOSE ; then
155+ echo " Token source: $TOKENFILE " >&2
156+ fi
143157fi
144158if [ -z " $TOKEN " ]; then
145159 echo " Token is empty" >&2
0 commit comments