Module: TalkToYourApp::Auth::Basic
- Defined in:
- lib/talk_to_your_app/auth/basic.rb
Overview
Validates an HTTP Basic credential by delegating to an operator-supplied callable ‘(username, password) -> truthy`. The gem makes no assumption about the host app’s user model. The username becomes the principal.
Class Method Summary collapse
Class Method Details
.principal_for(encoded, callable) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/talk_to_your_app/auth/basic.rb', line 13 def principal_for(encoded, callable) return nil if encoded.nil? || encoded.empty? || callable.nil? decoded = Base64.decode64(encoded) username, password = decoded.split(":", 2) return nil if username.nil? || username.empty? callable.call(username, password) ? username : nil end |