Class: PadlockAuth::Config
- Inherits:
-
Object
- Object
- PadlockAuth::Config
- Extended by:
- Option
- Includes:
- Mixins::BuildWith
- Defined in:
- lib/padlock_auth/config.rb,
lib/padlock_auth/config/option.rb,
lib/padlock_auth/config/scopes.rb
Overview
Configuration for PadlockAuth.
Defined Under Namespace
Modules: Option Classes: Builder, Scopes
Instance Attribute Summary collapse
-
#access_token_methods ⇒ Array<Symbol>
readonly
Methods to extract the access token from the request.
-
#default_scopes ⇒ PadlockAuth::Config::Scopes
readonly
Default required scopes, used whenever ‘padlock_authorize!` is called without arguments.
-
#handle_auth_errors ⇒ Symbol
readonly
How to handle authentication errors.
-
#realm ⇒ String
readonly
WWW-Authenticate Realm (default “PadlockAuth”).
-
#strategy ⇒ PadlockAuth::AbstractStrategy
readonly
The strategy to use for authentication.
Class Method Summary collapse
-
.build { ... } ⇒ PadlockAuth::Config
Builds the configuration instance using the builder.
Instance Method Summary collapse
- #action_cable_methods ⇒ Object
-
#raise_on_errors? ⇒ Boolean
Whether to raise an exception when authentication fails.
-
#render_on_errors? ⇒ Boolean
Whether to render an error response when authentication fails.
-
#validate! ⇒ Object
private
Called by PadlockAuth::Utils::AbstractBuilder#build to validate the configuration.
Methods included from Option
Instance Attribute Details
#access_token_methods ⇒ Array<Symbol> (readonly)
Methods to extract the access token from the request.
166 167 168 169 170 171 172 |
# File 'lib/padlock_auth/config.rb', line 166 def access_token_methods @access_token_methods ||= i[ from_access_token_param from_bearer_param ] end |
#default_scopes ⇒ PadlockAuth::Config::Scopes (readonly)
Default required scopes, used whenever ‘padlock_authorize!` is called without arguments.
Empty by default.
154 155 156 |
# File 'lib/padlock_auth/config.rb', line 154 def default_scopes @default_scopes ||= PadlockAuth::Config::Scopes.new end |
#handle_auth_errors ⇒ Symbol (readonly)
How to handle authentication errors.
-
‘:raise` - Raise an exception when authentication fails
-
‘:render` - Render an error response when authentication fails
190 |
# File 'lib/padlock_auth/config.rb', line 190 option :handle_auth_errors, default: :render |
#realm ⇒ String (readonly)
WWW-Authenticate Realm (default “PadlockAuth”).
136 |
# File 'lib/padlock_auth/config.rb', line 136 attr_reader :strategy |
#strategy ⇒ PadlockAuth::AbstractStrategy (readonly)
The strategy to use for authentication.
136 137 138 |
# File 'lib/padlock_auth/config.rb', line 136 def strategy @strategy end |
Class Method Details
.build { ... } ⇒ PadlockAuth::Config
Builds the configuration instance using the builder.
126 |
# File 'lib/padlock_auth/config.rb', line 126 build_with Builder |
Instance Method Details
#action_cable_methods ⇒ Object
174 175 176 177 178 179 |
# File 'lib/padlock_auth/config.rb', line 174 def action_cable_methods @action_cable_methods ||= i[ from_access_token_param from_bearer_param ] end |
#raise_on_errors? ⇒ Boolean
Returns Whether to raise an exception when authentication fails.
200 201 202 |
# File 'lib/padlock_auth/config.rb', line 200 def raise_on_errors? handle_auth_errors == :raise end |
#render_on_errors? ⇒ Boolean
Returns Whether to render an error response when authentication fails.
194 195 196 |
# File 'lib/padlock_auth/config.rb', line 194 def render_on_errors? handle_auth_errors == :render end |
#validate! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Called by PadlockAuth::Utils::AbstractBuilder#build to validate the configuration.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/padlock_auth/config.rb', line 210 def validate! raise ArgumentError, "strategy has not been configured via secure_with" if strategy.nil? raise ArgumentError, "realm is required" if realm.blank? unless handle_auth_errors.in? i[raise render] raise ArgumentError, "handle_auth_errors must be :raise, or :render" end true end |