3

Im trying to authenticate to github via a github api in vue js but it returns a 401 unauthorized error,any ideas

 sendDetails(e){
      e.preventDefault();
      let that=this;
      var b=that.username+':'+that.password;
      var encodedAuth=b.toString('base64');
      console.log(encodedAuth);
        that.$http.post('https://api.github.com/user',{
            headers: {
                'Authorization' : encodedAuth
            }
        })
        .then(function(response){
           console.log(response);
        });
  }

but the same format works using curl

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
Cliff Ireri
  • 47
  • 1
  • 7
  • Basic authentication also prefixes the credentials with `Basic` https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization#Examples Perhaps this solves the problem. – Stephan-v Oct 02 '18 at 12:33

1 Answers1

0

Try:

sendDetails(e){
  e.preventDefault();
  let that=this;
  var b=that.username+':'+that.password;
  var encodedAuth=b.toString('base64');
  console.log(encodedAuth);
    that.$http.post('https://api.github.com/user',{
        headers: {
            'Authorization': 'Basic ' + encodedAuth
        }
    })
    .then(function(response){
       console.log(response);
    });
}
m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
runnerpaul
  • 5,942
  • 8
  • 49
  • 118