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
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);
});
}