Slide 62
Slide 62 text
var url = 'http://localhost:8000/login/',
creds = {
username: 'admin',
password: 'abc123'
};
$.post(url, creds, function(auth) {
$.ajax({
type: 'GET',
url: 'http://localhost:8000/restricted/',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Bearer " + auth.token);
},
success: function(data){
console.log(data);
// {
// foo: "bar"
// }
}
});
});