From 4097a6c4c07bd81a49776a86d419679a482d51f1 Mon Sep 17 00:00:00 2001 From: Onno Zweers Date: Fri, 3 Oct 2025 10:51:55 +0200 Subject: [PATCH 1/5] If filename is "-", read token from stdin. --- view-token | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/view-token b/view-token index e8fd002..912f428 100755 --- a/view-token +++ b/view-token @@ -344,13 +344,18 @@ done if [ -n "$tokenfile" ] ; then - $verbose && echo "Token source: $tokenfile" # # Read the tokenfile only once (It might be a file descriptor that will be closed after reading) - tokenfile_contents=$(<"$tokenfile") || { - echo "ERROR: unable to read token from '$tokenfile'" 1>&2 - exit 1 - } + if [ "$tokenfile" = "-" ]; then + echo "Reading token from stdin..." 1>&2 + tokenfile_contents=$(cat) + else + $verbose && echo "Token source: $tokenfile" + tokenfile_contents=$(<"$tokenfile") || { + echo "ERROR: unable to read token from '$tokenfile'" 1>&2 + exit 1 + } + fi # # First, we assume the tokenfile is an Rclone config file. token=$(sed -n 's/^bearer_token *= *//p' <<<"$tokenfile_contents") From 9c45baad1c77da40c8a0aafb97d5de1dc5031f7e Mon Sep 17 00:00:00 2001 From: Onno Zweers Date: Fri, 3 Oct 2025 13:13:18 +0200 Subject: [PATCH 2/5] Update help text --- view-token | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/view-token b/view-token index 912f428..18becfe 100755 --- a/view-token +++ b/view-token @@ -13,10 +13,11 @@ usage() { - file containing a token. Can be a plain text file with the bare token, or an Rclone config file. In that case, view-token will search for a line containing "bearer_token" and decode the value. - You can use a trick like this: + If filename is "-" (dash), view-token will read the token from stdin. + To read the token in a safe way from an environment variable, + you can use this trick: view-token <(cat <<<"\$my_token") - This allows you to read from a variable without exposing the variable - to other users with the ps command. + This will not expose your token to other users with the ps command. - view-token will look for environment variable BEARER_TOKEN and decode its value. From 8b606883579192e22c3594333201b2b152b47e0d Mon Sep 17 00:00:00 2001 From: Onno Zweers Date: Mon, 6 Oct 2025 17:32:34 +0200 Subject: [PATCH 3/5] Hide pasted token; end input with Enter key instead of Ctrl+D Also added a check if the input is empty. --- view-token | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/view-token b/view-token index 18becfe..7e68253 100755 --- a/view-token +++ b/view-token @@ -348,8 +348,8 @@ if [ -n "$tokenfile" ] ; then # # Read the tokenfile only once (It might be a file descriptor that will be closed after reading) if [ "$tokenfile" = "-" ]; then - echo "Reading token from stdin..." 1>&2 - tokenfile_contents=$(cat) + echo "Reading token from stdin. Input is not shown. Continue with the Enter key." 1>&2 + read -s tokenfile_contents else $verbose && echo "Token source: $tokenfile" tokenfile_contents=$(<"$tokenfile") || { @@ -382,4 +382,9 @@ else # read BEARER_TOKEN fi +if [ -z "$token" ] ; then + echo 1>&2 "ERROR: token is empty." + exit 1 +fi + check_token "$token" || exit 1 From 3fe85b88c421fd1d1536af5e19af40b1bfc3b8ed Mon Sep 17 00:00:00 2001 From: Onno Zweers Date: Mon, 6 Oct 2025 17:40:12 +0200 Subject: [PATCH 4/5] Updated example of reading token from environment var --- view-token | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view-token b/view-token index 7e68253..bbf11eb 100755 --- a/view-token +++ b/view-token @@ -16,7 +16,7 @@ usage() { If filename is "-" (dash), view-token will read the token from stdin. To read the token in a safe way from an environment variable, you can use this trick: - view-token <(cat <<<"\$my_token") + view-token - <<<"\$my_token" This will not expose your token to other users with the ps command. - view-token will look for environment variable BEARER_TOKEN From dbc9c7e5b6b61df18b5c63fded994b988fa74cc7 Mon Sep 17 00:00:00 2001 From: Onno Zweers Date: Mon, 6 Oct 2025 17:44:56 +0200 Subject: [PATCH 5/5] Hide prompt when --minimal was specified --- view-token | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view-token b/view-token index bbf11eb..b51e01c 100755 --- a/view-token +++ b/view-token @@ -348,7 +348,7 @@ if [ -n "$tokenfile" ] ; then # # Read the tokenfile only once (It might be a file descriptor that will be closed after reading) if [ "$tokenfile" = "-" ]; then - echo "Reading token from stdin. Input is not shown. Continue with the Enter key." 1>&2 + $verbose && echo "Reading token from stdin. Input is not shown. Continue with the Enter key." 1>&2 read -s tokenfile_contents else $verbose && echo "Token source: $tokenfile"