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

Add support for customizable user authentication #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

olivier-thatch
Copy link
Contributor

Add support for customizable user authentication via a new user_authentication configuration value.

When set, the value should be a proc or other callable object. The proc will receive the username as its sole argument, and should raise an exception if authentication fails.

For example:

    config.console1984.user_authentication = ->(username) do
      user = User.find_by(username: username)
      password = $stdin.getpass("Password: ")

      if user.nil? || !user.valid_password?(password) || !user.is_admin?
        # maybe log the attempt somehow?
        raise "Authentication failed"
      end
    end

Closes #103.

@jorgemanrubia Let me know what you think of this approach! I gave it a try in our actual Rails app with a variant of the example proc above, and AFAICT it works fine. Raising an exception is a bit rough because when authentication fails it prints the whole backtrace, but that's already the case when the gem raises Console1984::Errors::MissingUsername so 🤷

@olivier-thatch
Copy link
Contributor Author

cc @mark-kraemer since you were interested in this feature, curious if you have any feedback

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

Successfully merging this pull request may close these issues.

Add password protection in console sessions
1 participant