Skip to content

Instantly share code, notes, and snippets.

@ivermac
Created August 1, 2018 14:45
Show Gist options
  • Save ivermac/922def70ed9eaf83799b68ab1a587595 to your computer and use it in GitHub Desktop.
Save ivermac/922def70ed9eaf83799b68ab1a587595 to your computer and use it in GitHub Desktop.
Using fetch with basic auth
let username = 'john';
let password = 'doe';
let url = `https://httpbin.org/basic-auth/${username}/${password}`
let authString = `${username}:${password}`
let headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(authString))
fetch(url,{method: 'GET', headers: headers})
    .then(function (response) {
        console.log (response)
        return response
    });
@lowcrawler
Copy link

"btoa is not defined" when this code gets used in a Node14 lambda on AWS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment