Last active
April 2, 2023 10:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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