Permalink
Browse files

Added OAuth 2 compatibility

  • Loading branch information...
1 parent a37d995 commit b9d31f2adc0882ad82e284f5264e564b986db73b @alexadkins alexadkins committed Aug 1, 2013
Showing with 313 additions and 118 deletions.
  1. +186 −102 app.js
  2. +19 −2 public/data/apiconfig.json
  3. +32 −0 public/data/rdio.json
  4. +32 −0 public/data/rdio2.json
  5. +10 −1 public/javascripts/docs.js
  6. +21 −9 public/javascripts/livedocs.js
  7. +4 −1 views/api.jade
  8. +9 −3 views/authSuccess.jade
View
288 app.js

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -51,7 +51,7 @@
"keyParam":""
},
"rdio": {
- "name": "rdio",
+ "name": "Rdio (client_credentials)",
"protocol": "https",
"baseURL": "www.rdio.com",
"publicPath": "",
@@ -61,7 +61,24 @@
"type": "client_credentials",
"baseSite":"https://www.rdio.com/",
"accessTokenURL": "oauth2/token",
- "customHeaders": ""
+ "customHeaders": "Authoriation:",
+ "authorizationHeader":"Y"
+ },
+ "keyParam":""
+ },
+ "rdio2": {
+ "name": "Rdio (implicit)",
+ "protocol": "https",
+ "baseURL": "www.rdio.com",
+ "publicPath": "",
+ "privatePath": "/api/1",
+ "auth": "oauth2",
+ "oauth2": {
+ "type": "implicit",
+ "baseSite":"https://www.rdio.com/",
+ "accessTokenURL": "oauth2/authorize",
+ "customHeaders": "",
+ "authorizationHeader":"Y"
},
"keyParam":""
},
View
@@ -0,0 +1,32 @@
+{
+ "endpoints":[
+ {
+ "name":"Playlists",
+ "methods":[
+ {
+ "MethodName":"getPlaylists",
+ "Synopsis":"Returns a user’s playlists. If no user is specified then the current user will be used.",
+ "HTTPMethod":"POST",
+ "URI":"",
+ "RequiresOAuth":"Y",
+ "parameters":[
+ {
+ "Name":"method",
+ "Required":"Y",
+ "Default":"getPlaylists",
+ "Type":"string",
+ "Description":"Method name."
+ },
+ {
+ "Name":"user",
+ "Required":"Y",
+ "Default":"s422965",
+ "Type":"string",
+ "Description":"The user."
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
View
@@ -0,0 +1,32 @@
+{
+ "endpoints":[
+ {
+ "name":"Playlists",
+ "methods":[
+ {
+ "MethodName":"getPlaylists",
+ "Synopsis":"Returns a user’s playlists. If no user is specified then the current user will be used.",
+ "HTTPMethod":"POST",
+ "URI":"",
+ "RequiresOAuth":"Y",
+ "parameters":[
+ {
+ "Name":"method",
+ "Required":"Y",
+ "Default":"getPlaylists",
+ "Type":"string",
+ "Description":"Method name."
+ },
+ {
+ "Name":"user",
+ "Required":"Y",
+ "Default":"s422965",
+ "Type":"string",
+ "Description":"The user."
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
View
@@ -165,12 +165,21 @@
if (result.signin) {
window.open(result.signin,"_blank","height=900,width=800,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0");
}
- else{
+ else if (result.implicit) {
+ window.open(result.implicit,"_blank","height=900,width=800,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0");
+ }
+ else if (result.refresh) {
+ window.open(result.refresh,"_blank","height=900,width=800,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0");
+ }
+ else {
window.location.reload();
}
})
};
});
+
+ // $.('#access_token').val(foo);
+
/*
Try it! button. Submits the method params, apikey and secret if any, and apiName
@@ -38,21 +38,33 @@ var livedocs = (function() {
return data;
}
+ console.log('LIVEDOCS');
+ console.log(window.location.hash);
+
/**
* Handle OAuth success callback
*/
- ld.authSuccess = function(msg) {
- // window.location.reload();
- // console.log('Success!');
+ ld.authSuccess = function(msg, token) {
var credentials = $('section.credentials');
+ if (token) {
+ $('#accessToken').val(token.match(/access_token\=([^&]+)[&]?/)[1]);
+ $('h2', credentials).remove();
+ $('img', credentials).remove();
- $('h2', credentials).remove();
- $('img', credentials).remove();
+ credentials
+ .addClass('authed')
+ .append($(document.createElement('span')).text(msg))
+ .append($(document.createElement('img')).attr('src', '/images/accept.png'));
+ }
+ else {
+ $('h2', credentials).remove();
+ $('img', credentials).remove();
- credentials
- .addClass('authed')
- .append($(document.createElement('span')).text(msg))
- .append($(document.createElement('img')).attr('src', '/images/accept.png'));
+ credentials
+ .addClass('authed')
+ .append($(document.createElement('span')).text(msg))
+ .append($(document.createElement('img')).attr('src', '/images/accept.png'));
+ }
}
return ld;
View
@@ -12,6 +12,7 @@ block content
form#credentials
input(type='hidden', name='apiName', value=apiName)
- if (apiInfo.auth)
+ console.log(apiInfo)
section(class='credentials ' + authed)
- if (authed && apiInfo.oauth)
span Authenticated with OAuth
@@ -86,11 +87,13 @@ block content
input(type='hidden', name='httpMethod', value=method.HTTPMethod)
input(type='hidden', name='oauth', value=secure)
input(type='hidden', name='methodUri', value=method.URI)
+ input(type='hidden', name='accessToken', id='accessToken')
span.description !{method.Synopsis}
br
br
- - if (method.parameters.length > 0)
+ //- if (method.parameters.length > 0)
+ - if (method.parameters)
table.parameters
thead
tr
View
@@ -1,6 +1,12 @@
extends layout
block content
h1= title
- script.
- window.parent.opener.livedocs.authSuccess('Authenticated with OAuth'); //Indicate to the parent page
- window.close();
+ - if (apiInfo.oauth)
+ script.
+ window.parent.opener.livedocs.authSuccess('Authenticated with OAuth'); //Indicate to the parent page
+ window.close();
+ - else
+ script.
+ var accToken = window.location.hash;
+ window.parent.opener.livedocs.authSuccess('Authenticated with OAuth2', accToken); //Indicate to the parent page
+ window.close();

0 comments on commit b9d31f2

Please sign in to comment.