Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added remove auth method and some notes to read me file + better retu…

…rn handling form main oauth method
  • Loading branch information...
commit f375fb066f913973148d816fb93dc9032cc7c4a7 1 parent f3ff91f
Marko Manninen markomanninen authored
13 README.md
View
@@ -133,12 +133,23 @@ If you do a lot of interaction with Google Analytics or other Google services, y
## Widgets (APIs)
-### Supported and tested list
+New: OAuth widget is to fully demonstate OAuth process on application. One should carefully explore source from ` https://github.com/mmstud/scribe-node/blob/master/src/widgets/OAuth.coffee `
+
+Using widget would be as simple as:
+
+ scribe = require('scribe-node').load(['OAuth'])
+ service = new scribe.OAuth(YOUR_STORAGE_HANDLER, 'analytics')
+ service.get_authorization_url((url) -> console.log url)
+ service.set_verification_code('code', (response) -> console.log response)
+ access_token = service.get_access_token()
+
+### Supported and tested widget list
These are the specialized APIs that are already implemented on scribe-node library. Althought limited list of APIs mentiond here, it doesnt mean to you cannot use library with any other web service available from internet. Library should work with all OAuth 1.0a and 2.0 schemes. If you have made your own API, please dont hesitate to fork this repository, add API as a widget to the library and send a pull request.
* GoogleApi
* GoogleApi2
+* OAuth
* TwitterApi ([fernandezpablo85](http://github.com/fernandezpablo85))
### Yet to be done list
41 lib/widgets/OAuth.js
View
@@ -74,7 +74,7 @@
if (service = this.create_service()) {
storage = this.init_storage();
if (service.getVersion() === "2.0") {
- callback(service.getAuthorizationUrl());
+ return callback(service.getAuthorizationUrl());
} else {
request_token_extract = function(response) {
var token;
@@ -84,10 +84,29 @@
console.log("Request token set: " + storage['request_token']);
return callback(service.getAuthorizationUrl(token));
};
- service.getRequestToken(request_token_extract);
+ return service.getRequestToken(request_token_extract);
}
+ } else {
+ return callback(false);
+ }
+ };
+
+ OAuth.prototype.remove_authorization = function() {
+ var service, storage;
+ if (!(service = this.create_service())) return false;
+ storage = this.init_storage();
+ if (service.getVersion() === "2.0") {
+ storage[this.api]['expires_in'] = null;
+ storage[this.api]['token_type'] = null;
+ storage[this.api]['refresh_token'] = null;
+ } else {
+ storage[this.api]['request_token'] = null;
+ storage[this.api]['request_secret'] = null;
}
- return callback(false);
+ storage[this.api]['code'] = null;
+ storage[this.api]['access_token'] = null;
+ storage[this.api]['access_secret'] = null;
+ return true;
};
OAuth.prototype.get_request_token = function() {
@@ -131,16 +150,17 @@
storage = this.init_storage();
if (service = this.create_service()) {
if (service.getVersion() === "1.0" && !storage['request_token']) {
- console.log("Please get authorization url and request token first");
+ return console.log("Please get authorization url and request token first");
} else if (code) {
storage['code'] = code;
console.log('Verification code set: ' + storage['code']);
- this.set_access_token(service, callback);
+ return this.set_access_token(service, callback);
} else {
- console.log("Verification code not found");
+ return console.log("Verification code not found");
}
+ } else {
+ return callback(false);
}
- return callback(false);
};
OAuth.prototype.get_access_token = function() {
@@ -172,12 +192,13 @@
console.log("Refreshed token: " + storage['access_token']);
return callback(true);
};
- service.getRefreshToken(access_token, refresh_token_extract);
+ return service.getRefreshToken(access_token, refresh_token_extract);
} else {
- console.log("Only OAuth 2.0 tokens can be refreshed.");
+ return console.log("Only OAuth 2.0 tokens can be refreshed.");
}
+ } else {
+ return callback(false);
}
- return callback(false);
};
return OAuth;
4 package.json
View
@@ -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.17",
+ "version": "0.0.18",
"homepage": "https://github.com/mmstud/scribe-node",
"keywords": ["scribe","oauth","web2.0","node.js","coffeescript","java","google","api"],
"licenses": [{
@@ -28,4 +28,4 @@
"engines": {
"node": "~0.4"
}
-}
+}
34 src/widgets/OAuth.coffee
View
@@ -4,8 +4,8 @@
# it can greatly simplify authorization routines on node.js/coffeescript apps, but one could also use it as
# a starting point to own handling.
#
-# - class / widget supports certain api on hood, but with optional services parameter any service can be used.
-# on that case provider class must extend scribe DefaultAPi10a or DefaultAPi20 to work right way
+# - class / widget supports certain api on hood, but with optional services parameter any web service / API can be used.
+# on that case provider class must extend scribe DefaultApi10a or DefaultApi20 to work right way
# - default services can be configured with environment variables
# - storage could be any form of storage, session, redis db and so forth that just has "on set" and "on get" event
# handlers. in case of hubot you can pass robot.brain.data to store oauth tokens
@@ -16,8 +16,12 @@
# callback function to return true/false
# 4. get_request_token, get_access_token and get_verifier methods to retrieve tokens as per method name
#
-# TODO: signatureType on default service configurations is not used yet, but its possible and maybe
-# required on some services because default will be Header type.
+# TODO:
+# - signatureType on default service configurations is not used yet, but its possible and maybe
+# required on some services because default will be "Header" type
+# - its unclear how expired_in should be used
+# - at the moment callbacks return only true/false or authorization url. on some cases more information
+# could be served so returned object could be associated array of values. but so far I try to keep it silly simple
root = exports ? this
# require main library and apis
@@ -78,7 +82,23 @@ class root.OAuth
console.log "Request token set: " + storage['request_token']
callback service.getAuthorizationUrl token
service.getRequestToken request_token_extract
- callback false
+ else callback false
+
+ remove_authorization: () ->
+ if not service = @create_service()
+ return false
+ storage = @init_storage()
+ if service.getVersion() == "2.0"
+ storage[@api]['expires_in'] = null
+ storage[@api]['token_type'] = null
+ storage[@api]['refresh_token'] = null
+ else
+ storage[@api]['request_token'] = null
+ storage[@api]['request_secret'] = null
+ storage[@api]['code'] = null
+ storage[@api]['access_token'] = null
+ storage[@api]['access_secret'] = null
+ return true
get_request_token: () ->
new scribe.Token @storage.oauth[@api]['request_token'], @storage.oauth[@api]['request_secret']
@@ -123,7 +143,7 @@ class root.OAuth
@set_access_token service, callback
else
console.log "Verification code not found"
- callback false
+ else callback false
get_access_token: () ->
storage = @init_storage()
@@ -155,4 +175,4 @@ class root.OAuth
service.getRefreshToken access_token, refresh_token_extract
else
console.log "Only OAuth 2.0 tokens can be refreshed."
- callback false
+ else callback false
Please sign in to comment.
Something went wrong with that request. Please try again.