From 22402db273436563744ee3170bbba87c4bb6505b Mon Sep 17 00:00:00 2001 From: ciaranj Date: Mon, 19 Apr 2010 13:20:50 +0100 Subject: [PATCH] Ok, very basic, needs refactoring Getting of Request and Access tokens (POST stylee) works. --- Makefile | 9 + lib/oauth.js | 756 ++++---------- lib/sha1.js | 324 ++++-- seed.yml | 5 + spec/lib/images/bg.png | Bin 0 -> 154 bytes spec/lib/images/hr.png | Bin 0 -> 321 bytes spec/lib/images/loading.gif | Bin 0 -> 2608 bytes spec/lib/images/sprites.bg.png | Bin 0 -> 4876 bytes spec/lib/images/sprites.png | Bin 0 -> 3629 bytes spec/lib/images/vr.png | Bin 0 -> 145 bytes spec/lib/jspec.css | 149 +++ spec/lib/jspec.growl.js | 115 +++ spec/lib/jspec.jquery.js | 71 ++ spec/lib/jspec.js | 1775 ++++++++++++++++++++++++++++++++ spec/lib/jspec.shell.js | 39 + spec/lib/jspec.timers.js | 90 ++ spec/lib/jspec.xhr.js | 193 ++++ spec/node.js | 33 + spec/spec.oauth.js | 14 + spec/spec.sha1.js | 15 + 20 files changed, 2956 insertions(+), 632 deletions(-) create mode 100644 Makefile create mode 100644 seed.yml create mode 100644 spec/lib/images/bg.png create mode 100644 spec/lib/images/hr.png create mode 100644 spec/lib/images/loading.gif create mode 100644 spec/lib/images/sprites.bg.png create mode 100644 spec/lib/images/sprites.png create mode 100644 spec/lib/images/vr.png create mode 100644 spec/lib/jspec.css create mode 100644 spec/lib/jspec.growl.js create mode 100644 spec/lib/jspec.jquery.js create mode 100644 spec/lib/jspec.js create mode 100644 spec/lib/jspec.shell.js create mode 100644 spec/lib/jspec.timers.js create mode 100644 spec/lib/jspec.xhr.js create mode 100644 spec/node.js create mode 100644 spec/spec.oauth.js create mode 100644 spec/spec.sha1.js diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..74a791d --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ + +NODE = node + +all: test + +test: + @$(NODE) spec/node.js all + +.PHONY: test \ No newline at end of file diff --git a/lib/oauth.js b/lib/oauth.js index b319612..74382b1 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -1,548 +1,232 @@ -/* - * Copyright 2008 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +var sha1= require('./sha1'), + http= require('http'); -/* Here's some JavaScript software for implementing OAuth. +exports.OAuth= function(requestUrl, accessUrl, authorizeUrl, consumerKey, consumerSecret, version, signatureMethod) { + this._requestUrl= requestUrl; + this._accessUrl= accessUrl; + this._authorizeUrl= authorizeUrl; + this._consumerKey= consumerKey; + this._consumerSecret= this._encodeData( consumerSecret ); + this._version= version; + this._signatureMethod= signatureMethod; +}; - This isn't as useful as you might hope. OAuth is based around - allowing tools and websites to talk to each other. However, - JavaScript running in web browsers is hampered by security - restrictions that prevent code running on one website from - accessing data stored or served on another. - - Before you start hacking, make sure you understand the limitations - posed by cross-domain XMLHttpRequest. - - On the bright side, some platforms use JavaScript as their - language, but enable the programmer to access other web sites. - Examples include Google Gadgets, and Microsoft Vista Sidebar. - For those platforms, this library should come in handy. -*/ - -// The HMAC-SHA1 signature method calls b64_hmac_sha1, defined by -// http://pajhome.org.uk/crypt/md5/sha1.js - -/* An OAuth message is represented as an object like this: - {method: "GET", action: "http://server.com/path", parameters: ...} - - The parameters may be either a map {name: value, name2: value2} - or an Array of name-value pairs [[name, value], [name2, value2]]. - The latter representation is more powerful: it supports parameters - in a specific sequence, or several parameters with the same name; - for example [["a", 1], ["b", 2], ["a", 3]]. - - Parameter names and values are NOT percent-encoded in an object. - They must be encoded before transmission and decoded after reception. - For example, this message object: - {method: "GET", action: "http://server/path", parameters: {p: "x y"}} - ... can be transmitted as an HTTP request that begins: - GET /path?p=x%20y HTTP/1.0 - (This isn't a valid OAuth request, since it lacks a signature etc.) - Note that the object "x y" is transmitted as x%20y. To encode - parameters, you can call OAuth.addToURL, OAuth.formEncode or - OAuth.getAuthorization. - - This message object model harmonizes with the browser object model for - input elements of an form, whose value property isn't percent encoded. - The browser encodes each value before transmitting it. For example, - see consumer.setInputs in example/consumer.js. - */ - -/* This script needs to know what time it is. By default, it uses the local - clock (new Date), which is apt to be inaccurate in browsers. To do - better, you can load this script from a URL whose query string contains - an oauth_timestamp parameter, whose value is a current Unix timestamp. - For example, when generating the enclosing document using PHP: - -