module SimpleTokenAuth::AuthenticateWithToken

Public Instance Methods

method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/simple_token_auth/authenticate_with_token.rb, line 13
def method_missing(method, *args, &block)
  if m = method.to_s.match(/authenticate_(.+)_from_token!/)
    send :authenticate_from_token!, m[1]
  else
    super
  end
end

Private Instance Methods

after_authenticated(*args) click to toggle source
# File lib/simple_token_auth/authenticate_with_token.rb, line 42
def after_authenticated(*args)
  SimpleTokenAuth.after_authenticated(*args)
end
authenticate_from_token!(scope_name) click to toggle source
# File lib/simple_token_auth/authenticate_with_token.rb, line 23
def authenticate_from_token!(scope_name)
  scope_class = scope_name.camelize.constantize
  authenticate_or_request_with_http_token do |token, options|
    return false if token.blank?

    scope, token  = *find_scope(scope_class, token)
    authenticated = false

    if scope
      api_key = scope.api_key
      authenticated = api_key && !api_key.expired? && compare_token(api_key.access_token, token)
    end

    after_authenticated(scope, self) if authenticated

    authenticated
  end
end
compare_token(a, b) click to toggle source
# File lib/simple_token_auth/authenticate_with_token.rb, line 50
def compare_token(a, b)
  SimpleTokenAuth.compare_token(a, b)
end
find_scope(*args) click to toggle source
# File lib/simple_token_auth/authenticate_with_token.rb, line 46
def find_scope(*args)
  SimpleTokenAuth.find_scope(*args)
end