From github api documentation
Create a new repository for the authenticated user.
POST /user/repos Create a new repository in this organization. The authenticated user must be a member of the specified organization.
POST /orgs/:org/repos OAuth scope requirements
When using OAuth, authorizations must include:
public_repo scope or repo scope to create a public repository repo scope to create a private repository
curl -i -H 'Authorization: token xxxxxxxxxxxxxxxxxxxxxxx' -d '{"name":":test-repo"}' https://api.github.com/orgs/test-org/repos
Using the curl command, it works fine, but how do we replicate that in angular using the $resource service with post method. Below is what i have, and i get a "bad credentials error" even if i use the same token using curl and successfully created a repo in the organization, "test-org". If i include the access token in the header like headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', access_token:'xxxxxx....xxxx'}, then i get a CORS error. ps: access_token....the 40 chars personal access token & the person is a member of the org, "test-org" For get method, it works fine as expected but the problem is with post method.
var headers = {}
headers = {'Content-Type': 'application/x-www-form-urlencoded;
charset=UTF-8'},
var access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
var factory = $resource('https://api.github.com/orgs/:org/repos',
{
org:'test-org',callback: 'JSON_CALLBACK',
access_token:access_token}, {
create: {
method: 'POST',
params: {
name: 'test-repo',
description: 'this is blabla'},
headers: headers
},
get: {
method: 'JSONP',
headers: headers
}
}
);
return factory;