Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now supporting 2- and 3-leg oauth

  • Loading branch information...
commit e0000a4b1c5285e1aba71b51695b34f3fcfd2685 1 parent 04a004a
erik authored
Showing with 59 additions and 68 deletions.
  1. +0 −68 oauth/2leg.xml
  2. +59 −0 oauth/oauth.xml
View
68 oauth/2leg.xml
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
- <meta>
- <author>Erik Eldridge</author>
- <sampleQuery>select * from {table} where uri='http://example.com' and key='asd123' and secret='zxc456';</sampleQuery>
- <!-- ref: http://developer.yahoo.com/yql/guide/yql-execute-examples.html#yql-execute-example-oauth-netflix -->
- </meta>
- <bindings>
- <select itemPath="" produces="XML">
- <inputs>
- <key id="method" type="xs:string" paramType="variable" default="GET"/>
- <key id="uri" type="xs:string" paramType="variable" required="true"/>
- <key id="key" type="xs:string" paramType="variable" required="true"/>
- <key id="secret" type="xs:string" paramType="variable" required="true"/>
- </inputs>
- <execute><![CDATA[
-
- //kludge: oauth lib depends on document.getElementsByTagName (i know!)
- var document = {
- getElementsByTagName: function() {}
- };
-
- y.include("http://oauth.googlecode.com/svn/code/javascript/oauth.js");
- y.include("http://oauth.googlecode.com/svn/code/javascript/sha1.js");
- y.include('http://github.com/kvz/phpjs/raw/master/functions/url/parse_url.js');
-
- var accessor = {
- consumerSecret: secret,
- tokenSecret: ""
- };
- var message = {
- action: uri,
- method: method,
- parameters: [
- ["oauth_consumer_key", key],
- ["oauth_version", "1.0"]]
- };
- var parsed = parse_url(uri);
- var realm = parsed['scheme'] + '://' + parsed['host']
- OAuth.setTimestampAndNonce(message);
- OAuth.SignatureMethod.sign(message, accessor);
- var req = y.rest(uri).header("Authorization", OAuth.getAuthorizationHeader(realm, message.parameters));
-
- try {
- switch (method) {
- case 'POST':
- response.object = req.post().response;
- break;
- case 'PUT':
- response.object = req.put().response;
- break;
- case 'DELETE':
- response.object = req.del().response;
- break;
- default:
- response.object = req.get().response;
- }
- } catch(err) {
- response.object = {
- 'result': 'failure',
- 'error': err
- };
- }
-
- ]]></execute>
- </select>
- </bindings>
-</table>
View
59 oauth/oauth.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>Erik Eldridge</author>
+ <sampleQuery>select * from {table} where uri='http://example.com' and consumerKey='asd123' and consumerSecret='zxc456' and callbackUri='http://example.com';</sampleQuery>
+ <documentationURL>http://wiki.github.com/erikeldridge/yql-oauth-support/</documentationURL>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <inputs>
+ <key id="method" type="xs:string" paramType="variable" default="GET"/>
+ <key id="uri" type="xs:string" paramType="variable" required="true"/>
+ <key id="consumerKey" type="xs:string" paramType="variable" required="true"/>
+ <key id="consumerSecret" type="xs:string" paramType="variable" required="true"/>
+ <key id="callbackUri" type="xs:string" paramType="variable"/>
+ <key id="token" type="xs:string" paramType="variable"/>
+ <key id="tokenSecret" type="xs:string" paramType="variable"/>
+ <key id="verifier" type="xs:string" paramType="variable"/>
+ </inputs>
+ <execute><![CDATA[
+
+ y.include( "http://github.com/yql/yql-tables/raw/master/oauth/oauth.utils.js" );
+ y.include( 'http://github.com/kvz/phpjs/raw/master/functions/url/parse_url.js' );
+
+ var parsed = parse_url( uri );
+ var accessor = {
+ consumerKey: consumerKey,
+ consumerSecret: consumerSecret,
+ token: "",
+ tokenSecret: "",
+ realm: parsed['scheme'] + '://' + parsed['host']
+ };
+
+ if ( token ) {
+ accessor.token = token;
+ }
+ if ( tokenSecret ) {
+ accessor.tokenSecret = tokenSecret;
+ }
+
+ var args = {
+ method: method,
+ accessor: accessor,
+ parameters:[]
+ };
+
+ if ( callbackUri ) {
+ args.parameters.push( [ "oauth_callback", callbackUri ] );
+ }
+ if ( verifier ) {
+ args.parameters.push( [ "oauth_verifier", verifier ] );
+ }
+
+ var request = y.rest( uri );
+ response.object = sendRequest( args );
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
Please sign in to comment.
Something went wrong with that request. Please try again.