1

In github, there's this section where you can do basic auth... If I was using curl, this would look like:

$ curl -u <username>:<token> https://api.github.com/user

How do I turn that into http request if I were to do it in angular?

1 Answer 1

1

I finally managed to solve it. I based my answer from icodeya.

function authenticateUser(username, authtoken) {

  var url = "https://api.github.com/user"

  var credentials = btoa(username + ':' + authtoken);
  var authorization = {'Authorization': 'Basic ' + credentials};
  var header = { headers: authorization }

  return $http.get(url, header)
     .then( function(response) {
        function() { //do something here. }
     }
  );
}
Sign up to request clarification or add additional context in comments.

1 Comment

That's the way to do it! I'm curious about the token you're using, is it a JWT? And where are you storing it? I always want to help with front-end security :) if you're building a front-end app, you might find my blog articles useful: Token Based Authentication for Single Page Apps (SPAs) https://stormpath.com/blog/build-secure-user-interfaces-using-jwts/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.