Created
July 2, 2012 04:44
-
-
Save blackxored/3031146 to your computer and use it in GitHub Desktop.
Token authentication with Devise and Backbone
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
jQuery.ajaxSetup( | |
beforeSend: (xhr) -> | |
xhr.setRequestHeader('X-Auth-Token', | |
App.Session.getAuthenticationToken()) | |
) | |
# ... | |
class App.Session | |
# ... | |
getAuthenticationToken: -> | |
user = @getCurrentUser() | |
user.authenticationToken if user? | |
# ... | |
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
module Devise | |
module Strategies | |
class TokenAuthenticatable < Authenticatable | |
# TODO: Monkey-patch for allowing X-Auth-Token in headers | |
private | |
def params_auth_hash_with_headers | |
if request.headers['X-Auth-Token'] | |
params.merge!({ :auth_token => request.headers['X-Auth-Token']}) | |
end | |
params_auth_hash_without_headers | |
end | |
alias_method :params_auth_hash_without_headers, :params_auth_hash | |
alias_method :params_auth_hash, :params_auth_hash_with_headers | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment