Last active
February 3, 2026 20:26
-
-
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/fdde60ac615e8f1cc5a777d3a1c576f7006d134d
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| ## 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