Skip to content

Commit

Permalink
rolling a new version
Browse files Browse the repository at this point in the history
better structuring of main script, new set access code method to oauth
widget, minor documentation changes
  • Loading branch information
markomanninen committed Nov 22, 2011
1 parent a0dbef3 commit 3eaf327
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 154 deletions.
151 changes: 77 additions & 74 deletions lib/scribe.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 29 additions & 10 deletions lib/widgets/OAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

root = typeof exports !== "undefined" && exports !== null ? exports : this;

scribe = require('../scribe').load(['GoogleApi', 'GoogleApi2', 'TwitterApi']);
scribe = require('../scribe').load(['GoogleApi', 'GoogleApi2', 'TwitterApi', 'FacebookApi']);

env = process.env;

Expand Down Expand Up @@ -33,6 +33,14 @@
'callback': 'oob'
};

default_services['facebook'] = {
'provider': scribe.FacebookApi,
'key': env.FACEBOOK_OAUTH_API_KEY,
'secret': env.FACEBOOK_OAUTH_API_SECRET,
'scope': 'email,read_stream,read_insights',
'callback': 'https://www.facebook.com/connect/login_success.html'
};

root.OAuth = (function() {

function OAuth(storage, api, services) {
Expand All @@ -59,7 +67,7 @@
}
};

OAuth.prototype.init_storage = function() {
OAuth.prototype._init_storage = function() {
if (!this.storage.oauth) {
this.storage.oauth = [];
this.storage.oauth[this.api] = [];
Expand All @@ -72,7 +80,7 @@
OAuth.prototype.get_authorization_url = function(callback) {
var request_token_extract, service, storage;
if (service = this.create_service()) {
storage = this.init_storage();
storage = this._init_storage();
if (service.getVersion() === "2.0") {
return callback(service.getAuthorizationUrl());
} else {
Expand All @@ -94,7 +102,7 @@
OAuth.prototype.remove_authorization = function() {
var service, storage;
if (!(service = this.create_service())) return false;
storage = this.init_storage();
storage = this._init_storage();
if (service.getVersion() === "2.0") {
delete storage['expires_in'];
delete storage['token_type'];
Expand All @@ -117,9 +125,20 @@
return new scribe.Verifier(this.storage.oauth[this.api]['code']);
};

OAuth.prototype.set_access_token = function(service, callback) {
OAuth.prototype.set_access_token_code = function(code) {
var service, storage;
if (service = this.create_service()) {
storage = this._init_storage();
storage['access_token'] = code;
console.log('Access token set: ' + storage['access_token']);
return true;
}
return false;
};

OAuth.prototype._set_access_token = function(service, callback) {
var access_token_extract, storage;
storage = this.init_storage();
storage = this._init_storage();
access_token_extract = function(response) {
var token;
token = service.api.getAccessTokenExtractor()(response.data);
Expand Down Expand Up @@ -147,14 +166,14 @@

OAuth.prototype.set_verification_code = function(code, callback) {
var service, storage;
storage = this.init_storage();
storage = this._init_storage();
if (service = this.create_service()) {
if (service.getVersion() === "1.0" && !storage['request_token']) {
return console.log("Please get authorization url and request token first");
} else if (code) {
storage['code'] = code;
console.log('Verification code set: ' + storage['code']);
return this.set_access_token(service, callback);
return this._set_access_token(service, callback);
} else {
return console.log("Verification code not found");
}
Expand All @@ -165,7 +184,7 @@

OAuth.prototype.get_access_token = function() {
var service, storage;
storage = this.init_storage();
storage = this._init_storage();
if (storage['access_token'] && (service = this.create_service())) {
if (service.getVersion() === "2.0") {
return new scribe.Token(storage['access_token'], "", "", storage['expires_in'], storage['token_type'], storage['refresh_token']);
Expand All @@ -182,7 +201,7 @@
var refresh_token_extract, service, storage;
if (access_token && (service = this.create_service())) {
if (service.getVersion() === "2.0") {
storage = this.init_storage();
storage = this._init_storage();
refresh_token_extract = function(response) {
var refresh_token;
refresh_token = service.api.getAccessTokenExtractor()(response.data);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "scribe-node",
"description": "Scribe java OAuth library port to node.js",
"author": "Marko Manninen <mmstud@gmail.com> (http://about.me/markomanninen)",
"version": "0.0.19",
"version": "0.0.20",
"homepage": "https://github.com/mmstud/scribe-node",
"keywords": ["scribe","oauth","web2.0","node.js","coffeescript","java","google","api"],
"licenses": [{
Expand Down

0 comments on commit 3eaf327

Please sign in to comment.