Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(function () { | ||
var _token = null; | ||
var verify_token = function (token) { | ||
if (token && token.match(/^[\-_a-zA-Z0-9]{98}$/)) { | ||
return $.ajax({ | ||
url: "https://alpha-api.<%= lanai_hostname %>/stream/0/token", | ||
headers: { | ||
"Authorization": "BEARER " + token | ||
} | ||
}).promise(); | ||
} else { | ||
return $.Deferred().reject().promise(); | ||
} | ||
}; | ||
|
||
var Auth = { | ||
login: function (new_token) { | ||
var deferred = $.Deferred(); | ||
|
||
var valid_token = verify_token(new_token); | ||
valid_token.fail(function () { | ||
if (_token === null && typeof(localStorage.token) !== 'undefined') { | ||
_token = JSON.parse(localStorage.token); | ||
} | ||
}).done(function () { | ||
debugger | ||
_token = { | ||
user_token: new_token | ||
}; | ||
localStorage.token = JSON.stringify(_token); | ||
}).always(function () { | ||
if (_token && _token.user_token) { | ||
deferred.resolve(_token); | ||
} else { | ||
deferred.reject(); | ||
} | ||
}); | ||
|
||
return deferred.promise(); | ||
}, | ||
logout: function () { | ||
localStorage.token = null; | ||
token = null; | ||
_is_logged_in = false; | ||
}, | ||
verify_token: verify_token | ||
}; | ||
|
||
ADN.auth = Auth; | ||
}()); | ||
|
||
$(function() { | ||
// make it easy to upgrade scopes, if there's a new token just log in with that even if we're already logged in | ||
var new_token = $.url(window.location).fparam('access_token'); | ||
var login = ADN.auth.login(new_token); | ||
|
||
login.fail(function () { | ||
$('.authorize-prompt').removeClass('hide'); | ||
}).done(function (token) { | ||
var needle = "<YOUR ACCESS TOKEN>"; | ||
$('pre code').each(function () { | ||
var el = $(this); | ||
el.html(el.html().replace(needle, token.user_token)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.