Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.0 Doesn't authentificate user from session #17

Open
panasyuk opened this issue Sep 28, 2015 · 1 comment
Open

1.0.0 Doesn't authentificate user from session #17

panasyuk opened this issue Sep 28, 2015 · 1 comment

Comments

@panasyuk
Copy link
Contributor

# application
class Application < Sinatra::Base
  register Sinatra::Warden
  set :use_oauth, false

  use Warden::Manager do |config|
    config.serialize_into_session{|user| user.id }
    config.serialize_from_session{|id| User.get(id) }
    config.scope_defaults :default, strategies: [:password], action: 'login'
    config.failure_app = self
  end

    Warden::Manager.before_failure do |env, opts|
      env['REQUEST_METHOD'] = 'GET'
    end
end
# strategy
require 'warden'
Warden::Strategies.add(:password) do
  def valid?
    params['user'] && params['user']['login'] && params['user']['password']
  end

  def authenticate!
    user = User.first login: params['user']['login'], password: params['user']['password']
    if user.nil?
      throw(:warden, message: "The username you entered does not exist.")
    elsif user.authenticate(params['user']['password'])
      success!(user)
    else
      throw(:warden, message: "The username and password combination ")
    end
  end
end
# user
class User
  def authenticate(attempted_password)
    true
  end
end

As i understood debugging the app, the password strategy successfully autheticates the user, but it doesn't put serialized user to the session.
This code worked on 0.3.2, but fails on 1.0.0.

@jsmestad
Copy link
Collaborator

Going to see if maybe @hassox can help you with this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants