Reputation: 1636
I am using the following function in order to get back the collaborators on a specific repository:
var getCol = function(username, reponame) {
var repo;
var repoUrl = "https://api.github.com/repos/" + username + "/" + reponame + "/collaborators";
return $http.get(repoUrl)
.then(function(response) {
return repo = response.data;
return $http.get(repoUrl + "/collaborators");
});
};
I need to authenticate in order to be able to access this sort of data. Supposing I have my client token by registering a new app at https://github.com/settings/applications.
How would I authenticate in Angular so I can fully use the API?
Upvotes: 2
Views: 141
Reputation: 10313
You should set a header with the data required to sign in to github when not using token based oauth signin. Once the headers are set, AngularJS will send them with every request. Haven't tried it but it should be something like this:
$http.defaults.headers.common["User"] = user;
$http.defaults.headers.common["Password"] = password;
To answer your comment:
Here you can get a token for your account
And use it like this:
$http.defaults.headers.common["Authorization"] = 'Basic' + yourApiToken;
This is not secure at all since you will be using your token to authenticate which you should not do if you are letting other users do this requests. Read some more here to do it right, you need to get the user to signin with their pass and username and send this data to get back a token for the users session.
Upvotes: 3