-
-
Save smilemakc/fdbd7977f88da1b480a3b8ce8fe04b6b to your computer and use it in GitHub Desktop.
Generating base64-encoded Authorization headers in a variety of languages
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
| httpClient.DefaultRequestHeaders.Authorization = | |
| new AuthenticationHeaderValue( | |
| "Basic", | |
| Convert.ToBase64String( | |
| System.Text.ASCIIEncoding.ASCII.GetBytes( | |
| string.Format("{0}:{1}", username, password)))); |
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
| $header = "Authorization: Basic " . base64_encode($username . ':' . $password); |
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
| base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') | |
| header = ("Authorization: Basic %s" % base64string) |
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
| $header = 'Authorization: Basic ' + Base64.encode64( username + ':' + password ).chomp |
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
| $.ajax | |
| ({ | |
| type: "GET", | |
| url: "https://www.example.com", | |
| dataType: 'json', | |
| headers: { | |
| "Authorization", btoa(username + ":" + password) | |
| }, | |
| data: '{}', | |
| success: function (){ | |
| ... | |
| } | |
| }); |
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
| var username = 'Test'; | |
| var password = '123'; | |
| var auth = 'Basic ' + new Buffer(username + ':' + password).toString('base64'); | |
| var header = {'Host': 'www.example.com', 'Authorization': auth}; | |
| var request = client.request('GET', '/', header); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Bash:
username='Test'
password='123'
credentials="$(echo -n "$username:$password" | base64)"
header="Authorization: Basic $credentials"