Skip to content
Browse files

Merge branch 'oath-support'

  • Loading branch information...
2 parents e9ca2c5 + bb87f79 commit 811d15f5395c1dcf963d7f812b72eb511432886b @fitzgen committed Jan 3, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 github.js
View
11 github.js
@@ -11,6 +11,8 @@
// The username and authentication token of the library's user.
authUsername,
authToken,
+ // The access token of OAuth user, can be used instead of authUsername + authToken
+ authAccessToken,
// To save keystrokes when we make JSONP calls to the HTTP API, we will keep
// track of the root from which all V2 urls extend.
@@ -45,6 +47,9 @@
if (authUsername && authToken) {
url += "&login=" + authUsername + "&token=" + authToken;
}
+ if (authAccessToken) {
+ url += "&access_token=" + authAccessToken;
+ }
script.setAttribute("src", apiRoot + url);
document.getElementsByTagName('head')[0].appendChild(script);
@@ -91,7 +96,7 @@
// This helper function will throw a TypeError if the library user is not
// properly authenticated. Otherwise, it silently returns.
authRequired = function (username) {
- if (!authUsername || !authToken || authUsername !== username) {
+ if ((!authUsername || !authToken || authUsername !== username) && !authAccessToken) {
throw new TypeError("gh: Must be authenticated to do that.");
}
},
@@ -127,9 +132,11 @@
// Authenticate as a user. Does not try to validate at any point; that job
// is up to each individual method, which calls `authRequired` as needed.
- gh.authenticate = function (username, token) {
+ // If using OAuth access token, you may pass `null` for `username` and `token` args.
+ gh.authenticate = function (username, token, accessToken) {
authUsername = username;
authToken = token;
+ authAccessToken = accessToken;
return this;
};

0 comments on commit 811d15f

Please sign in to comment.
Something went wrong with that request. Please try again.