diff --git a/README.md b/README.md index 498fcc5..0b081ce 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,28 @@ Source files are made with coffeescript as it provides seemingly cleaner and man npm install scribe-node -Next steps are to demostrate retrieving authorization token and use it on your application to access data from web service. See Google analytics example at the end of the read me file. Examples uses OAuth 1.0a scheme. Later OAuth 2.0 examples will be added. +## Widgets (APIs) -Note that I'm using offpage application mode for authorization. It means callback page is set to `oob` which causes service provider to show verification code on browser window. Then you need to paste code to your application manually. Approach is a little bit different on fully pledged web appliations, that can hide this part of the process behind the screen. +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']) + services = {} + services['analytics'] = {'provider': scribe.GoogleApi, 'key': '{YOUR_KEY}', 'secret': '{YOUR_SECRET}', 'scope': 'https://www.google.com/analytics/feeds/', 'callback': 'oob'} + service = new scribe.OAuth({}, 'analytics', services) + service.get_authorization_url((url) -> console.log url) + + # after getting code execute rest of the script + service.set_verification_code('{CODE}', (response) -> console.log response) + access_token = service.get_access_token() ## OAuth 1.0a Dance Snippets +Next steps are to demostrate retrieving authorization token in smaller pieces (if above method is not working for you for some reason) and use it on your application to access data from web service. See Google analytics example at the end of the read me file. Examples uses OAuth 1.0a scheme. Later OAuth 2.0 examples will be added. + +Note that I'm using offpage application mode for authorization. It means callback page is set to `oob` which causes service provider to show verification code on browser window. Then you need to paste code to your application manually. Approach is a little bit different on fully pledged web appliations, that can hide this part of the process behind the screen. + ### Get authorization url get_authorization_url = (service) -> @@ -131,20 +147,6 @@ And then from coffee eval loop: If you do a lot of interaction with Google Analytics or other Google services, you may want to create own model for more sophisticated approach, buts its beyond the scope of this work. -## Widgets (APIs) - -__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({}, '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. diff --git a/package.json b/package.json index 1208ec8..9575a19 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "scribe-node", "description": "Scribe java OAuth library port to node.js", "author": "Marko Manninen (http://about.me/markomanninen)", - "version": "0.0.20", + "version": "0.0.21", "homepage": "https://github.com/mmstud/scribe-node", "keywords": ["scribe","oauth","web2.0","node.js","coffeescript","java","google","api"], "licenses": [{ @@ -26,6 +26,6 @@ "coffee-script": ">=1.1.3" }, "engines": { - "node": "~0.4" + "node": ">= 0.4.7" } } \ No newline at end of file diff --git a/src/scribe.coffee b/src/scribe.coffee index 3c95f0a..223ffd8 100644 --- a/src/scribe.coffee +++ b/src/scribe.coffee @@ -21,7 +21,6 @@ crypto = require 'crypto' root.load = (apis) -> for api in apis root[api] = require('./widgets/' + api)[api] - #eval('root.'+api+' = require("./widgets/'+api+'").'+api) return this # Verifier class diff --git a/src/widgets/OAuth.coffee b/src/widgets/OAuth.coffee index 599ffa9..9494071 100644 --- a/src/widgets/OAuth.coffee +++ b/src/widgets/OAuth.coffee @@ -12,9 +12,10 @@ # - public methods by OAuth class are: # 1. get_authorization_url which takes callback function to return url / false # 2. set_verification_code which takes code and callback function to return true/false -# 3. refresh_access_token which is used by OAuth 2.0 schemes only and which takes access_token and +# 3. set_access_token_code which is used by OAuth 2.0 schemes only which takes code and return true/false +# 4. refresh_access_token which is used by OAuth 2.0 schemes only and which takes access_token and # callback function to return true/false -# 4. get_request_token, get_access_token and get_verifier methods to retrieve tokens as per method name +# 5. 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