aboutsummaryrefslogtreecommitdiff
path: root/home/.bashrc.d/jwt.sh
blob: 8f95e5d4087c0f35b8f1d787bd2abfb19e7c9438 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# https://gist.github.com/thomasdarimont/46358bc8167fce059d83a1ebdb92b0e7

decode_base64_url() {
  local len=$((${#1} % 4))
  local result="$1"
  if [[ $len -eq 2 ]]; then result="$1"'=='
  elif [[ $len -eq 3 ]]; then result="$1"'='
  fi
  echo "$result" | tr '_-' '/+' | openssl enc -d -base64
}

decode_jwt(){
   decode_base64_url "$(echo -n "$2" | cut -d "." -f "$1")" | jq .
}

# Decode JWT header
alias jwth="decode_jwt 1"

# Decode JWT Payload
alias jwtp="decode_jwt 2"