Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a500fc6

Browse files
committed
Add support for OAuth.
1 parent a58a140 commit a500fc6

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,28 @@ Github.js
44
Ever wanted to store a file on Github right from the browser? Here you are.
55

66

7-
Expose API for a given repository.
7+
Create a Github instance.
88

99
```js
1010
var github = new Github({
1111
username: "YOU_USER",
1212
password: "YOUR_PASSWORD",
1313
auth: "basic"
1414
});
15+
```
16+
17+
Or if you prefer OAuth, it looks like this:
1518

19+
```js
20+
var github = new Github({
21+
token: "OAUTH_TOKEN"
22+
auth: "oauth"
23+
});
24+
```
25+
26+
Expose API for a given repository.
27+
28+
```js
1629
var repo = github.getRepo(reponame);
1730
```
1831

github.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Github.js 0.4.0
1+
// Github.js 0.5.0
22
// (c) 2012 Michael Aufreiter, Development Seed
33
// Github.js is freely distributable under the MIT license.
44
// For all details and documentation:
@@ -9,13 +9,17 @@
99
var API_URL = 'https://api.github.com';
1010

1111
Github = window.Github = function(options) {
12-
var username = options.username;
13-
var password = options.password;
1412

1513
// Util
1614
// =======
1715

1816
function _request(method, path, data, cb) {
17+
function headers() {
18+
return options.auth == 'oauth'
19+
? { Authorization: 'Token '+ options.token }
20+
: { Authorization : 'Basic ' + Base64.encode(options.username + ':' + options.password) }
21+
}
22+
1923
$.ajax({
2024
type: method,
2125
url: API_URL + path,
@@ -24,7 +28,7 @@
2428
contentType: 'application/x-www-form-urlencoded',
2529
success: function(res) { cb(null, res); },
2630
error: function(err) { cb(err); },
27-
headers : { Authorization : 'Basic ' + Base64.encode(username + ':' + password) }
31+
headers : headers()
2832
});
2933
}
3034

@@ -156,7 +160,7 @@
156160
var data = {
157161
"message": message,
158162
"author": {
159-
"name": username
163+
"name": options.username
160164
},
161165
"parents": [
162166
parent

0 commit comments

Comments
 (0)