diff options
author | Himbeer <himbeer@disroot.org> | 2025-01-27 19:42:57 +0100 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2025-01-27 19:42:57 +0100 |
commit | b7bddf45168472822d70c38a7f513e07aafbdb65 (patch) | |
tree | 380e2c4631c32b90e3ba366e9e6f06464115cbce | |
parent | 411a11ec3d1b1713d0d75329545ed18512553b0f (diff) |
Add OAuth2 token rotation script
This script is useful for email login to accounts that require the use
of OAuth2.
-rwxr-xr-x | bin/oauthenticate | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/bin/oauthenticate b/bin/oauthenticate new file mode 100755 index 0000000..1d71992 --- /dev/null +++ b/bin/oauthenticate @@ -0,0 +1,15 @@ +#!/bin/bash + +set -eo pipefail + +if [ -z "$1" -o -z "$2" -o -z "$3" ]; then + echo "Usage: oauthenticate <token_uri> <client_id> <refresh_token_file>" + exit 1 +fi + +RTOK=$(cat "$3") + +RESP=$(curl -fsS -X POST "$1" -d "client_id=$2" -d "grant_type=refresh_token" -d "refresh_token=${RTOK}") + +echo "${RESP}" | jq -r .refresh_token > $3 +echo "${RESP}" | jq -r .access_token |