Module: Ask::Auth
- Defined in:
- lib/ask/auth.rb,
lib/ask/auth/version.rb,
lib/ask/auth/providers/env.rb,
lib/ask/auth/providers/file.rb,
lib/ask/auth/providers/oauth.rb,
lib/ask/auth/providers/database.rb,
lib/ask/auth/providers/rails_credentials.rb
Overview
Defined Under Namespace
Modules: Providers Classes: Configuration, InvalidCredential, MissingCredential
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|config| ... } ⇒ Object
- .reset_configuration! ⇒ Object
-
.resolve(name, user: nil) ⇒ Object
Walk providers in order and return the first non-nil credential.
Class Method Details
.configuration ⇒ Object
43 44 45 |
# File 'lib/ask/auth.rb', line 43 def configuration @configuration ||= default_configuration end |
.configure {|config| ... } ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ask/auth.rb', line 36 def configure config = Configuration.new yield config @configuration = config @configuration.freeze end |
.reset_configuration! ⇒ Object
47 48 49 |
# File 'lib/ask/auth.rb', line 47 def reset_configuration! @configuration = nil end |
.resolve(name, user: nil) ⇒ Object
Walk providers in order and return the first non-nil credential.
name-
Symbol or String identifying the credential (e.g.
:github_token) user-
Optional user record for per-user providers (Database, OAuth)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ask/auth.rb', line 54 def resolve(name, user: nil) name = name.to_s.strip return nil if name.empty? configuration.providers.each do |provider| value = provider.call(name, user: user) next if value.nil? normalized = normalize(value) return normalized unless normalized.nil? end raise MissingCredential, name end |