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

Feature: allow users to define their own authentication strategy #6

Open
Porcupine96 opened this issue Sep 1, 2017 · 0 comments
Open

Comments

@Porcupine96
Copy link

It would be nice if a user could define his or hers own authentication strategy.

We could create an abstract class like:

class HTTPBasicAuth
  abstract class AuthenticationStrategy
    abstract def authorize?(username : String, password : String): String?
  end
end

Then a user could write his own implementation:

  class MongoAuthenticationStrategy < AuthenticationStrategy
    def authorize?(username : String, password : String): String?
        # find a user in database and return his ID if it exists
    end
  end

In order to keep backward compatibility we could add another contructor to the HttpBasicAuth

  def initialize(@strategy : AuthenticationStrategy)
    initialize({} of String => String)
  end

and then in the authorize? method perform a check:

    if strategy = @strategy
      strategy.authorize?(username, password)
    else
      @credentials.authorize?(username, password)
    end

What do you think? If you like the idea I can make a pull request and leave it for you to review 😄

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

1 participant