Skip to content

Instantly share code, notes, and snippets.

@cadethacker
Last active May 1, 2022 16:58
Show Gist options
  • Save cadethacker/9e34955fae71e1450f6132a4954b7ecb to your computer and use it in GitHub Desktop.
Save cadethacker/9e34955fae71e1450f6132a4954b7ecb to your computer and use it in GitHub Desktop.
#!/bin/bash
# be very careful with newlines, too me a long time to find all the inserted newlines
# all the commands and strip them out.
# echo "======================="
# echo "generate long string for challenge"
# echo "======================="
# "code_verifier must contain only: alphanumeric, '-', '.', '_', '~'",
# code_verify must be between 43 and 128 characters
code_verifier=`openssl rand -base64 60 | tr -d "\n" |tr '/+' '_-' | tr -d '='`
echo "code_verifier: $code_verifier |"
# echo "======================="
# echo "Steps:"
# echo "1. convert string to sha256 sum which outputs hex"
# echo "2. convert hex to binary (xxd)"
# echo "3. base64 the binary 32 byte value"
# echo "4. convert to url encoding"
# echo "5. trim off = on the end"
# echo "which leaves a 43 char string"
# echo "======================="
code_challenge=`echo -n $code_verifier| sha256sum -z | head -c 64 | xxd -r -p - | base64 | tr '/+' '_-' | tr -d '='`
# this will also work - forget where I found this
#code_challenge=$(printf %s "${code_verifier}" | openssl dgst -sha256 -binary | base64 | sed 's/+/-/g; s/\//_/g; s/=//g';)
echo "code_challenge: $code_challenge"
echo -n $code_challenge |wc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment