Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/599ac838bb01a37d29d489570defa195 to your computer and use it in GitHub Desktop.
Save dacr/599ac838bb01a37d29d489570defa195 to your computer and use it in GitHub Desktop.
small shell function to generate a basic authentication Authentication token / published by https://github.com/dacr/code-examples-manager #754cb140-a435-4cfb-9b5c-44cea3e0a1b0/ec44770c9b719c6786c34e29b4b90dded49d6c0e
## summary : small shell function to generate a basic authentication Authentication token
## keywords : bash, token, credential, basic-auth, authentication, base64, encode, @testable
## publish : gist
## authors : David Crosson
## license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
## id : 754cb140-a435-4cfb-9b5c-44cea3e0a1b0
## created-on : 2021-02-01T07:05:52Z
## managed-by : https://github.com/dacr/code-examples-manager
## run-with : sh $file
basicAuthToken() {
USER=$1
PASS=$2
ENC=$(echo -n "$USER:$PASS" | base64)
echo "Basic $ENC"
}
TOKEN=$(basicAuthToken "root" "root")
if [ "$TOKEN" != "Basic cm9vdDpyb290" ]; then
echo "WRONG ENCODING"
exit 1
fi
echo "Authorization: $TOKEN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment