Skip to content

Commit

Permalink
#3 Making authentication optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Jun 23, 2012
1 parent e61498c commit eecf2b3
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,32 @@ var crudr, socket;
var cookie = getCookie("access_token");
var query = getQuery("access_token");

// if (window.location.hash.length == 0) {
if( typeof( cookie ) == "undefined" && typeof( query ) == "undefined" ){
var path = '{{authorize}}'+'?';
var queryParams = ['client_id=' + key,
'redirect_uri=' + window.location,
'response_type=token'];
var query = queryParams.join('&');
var url = path + query;
window.location= url;
} else if( typeof( query ) != "undefined" && query != "false" ) {
var expiry = getQuery("expires_in");
// save token in cookie...
setCookie("access_token", query, expiry);

// redirect to the url without the query
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.location = url;
} else if (query == "false") {
alert("CRUDr authentication failed");
}
options || (options = {});

if( typeof( options.auth ) != "undefined" && !options.auth ) {
// skip authentication
} else {
// if (window.location.hash.length == 0) {
if( typeof( cookie ) == "undefined" && typeof( query ) == "undefined" ){
var path = '{{authorize}}'+'?';
var queryParams = ['client_id=' + key,
'redirect_uri=' + window.location,
'response_type=token'];
var query = queryParams.join('&');
var url = path + query;
window.location= url;
} else if( typeof( query ) != "undefined" && query != "false" ) {
var expiry = getQuery("expires_in");
// save token in cookie...
setCookie("access_token", query, expiry);

// redirect to the url without the query
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
window.location = url;
} else if (query == "false") {
alert("CRUDr authentication failed");
}
}

},
sync : function(socket, req, callbacks) {
Expand Down

0 comments on commit eecf2b3

Please sign in to comment.