Skip to content

Instantly share code, notes, and snippets.

@ericraio
Last active August 29, 2015 14:26
Show Gist options
  • Save ericraio/31389f96ff3635ef8e8b to your computer and use it in GitHub Desktop.
Save ericraio/31389f96ff3635ef8e8b to your computer and use it in GitHub Desktop.
module Devise
module Strategies
class Token < Base
# For more info. visit here..
# http://kyan.com/blog/2013/10/11/devise-authentication-strategies
def valid?
token
end
# For this example, we are simply using token authentication
# via parameters. However, anyone could use Rails's token
# authentication features to get the token from a header.
def authenticate!
user = User.find_by_device_and_token(request.headers['X_MOBILE_DEVICE'], token)
if user.present?
User.current = user
success!(user)
else
fail!("Could not log in")
end
end
def token
return params['auth_token'] if params['auth_token']
header = request.headers["Authorization"]
return unless header
header.split("Token token=")[1]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment