Class: PadlockAuth::Token::Strategy
- Inherits:
-
AbstractStrategy
- Object
- AbstractStrategy
- PadlockAuth::Token::Strategy
- Extended by:
- Config::Option
- Includes:
- Mixins::BuildWith, Mixins::HideAttribute
- Defined in:
- lib/padlock_auth/token/strategy.rb
Overview
Strategy for token-based authentication.
This strategy compares a token from the request to a secret key.
It does not allow for scopes, so it will always return false for any required scopes.
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#secret_key ⇒ String
readonly
The secret key used to build and authenticate access tokens.
Class Method Summary collapse
-
.build { ... } ⇒ PadlockAuth::Token::Strategy
Builds the stratey instance.
Instance Method Summary collapse
-
#build_access_token(raw_token) ⇒ PadlockAuth::Token::AccessToken
Builds an access token from a raw token.
-
#build_access_token_from_credentials(_username, password) ⇒ PadlockAuth::Token::AccessToken
Builds an access token from username and password credentials.
-
#validate! ⇒ Object
private
Called by the builder to validate the configuration.
Methods included from Config::Option
Methods inherited from AbstractStrategy
#build_forbidden_token_response, #build_invalid_token_response
Instance Attribute Details
#secret_key ⇒ String (readonly)
The secret key used to build and authenticate access tokens.
41 |
# File 'lib/padlock_auth/token/strategy.rb', line 41 option :secret_key |
Class Method Details
.build { ... } ⇒ PadlockAuth::Token::Strategy
Builds the stratey instance.
32 |
# File 'lib/padlock_auth/token/strategy.rb', line 32 build_with Builder |
Instance Method Details
#build_access_token(raw_token) ⇒ PadlockAuth::Token::AccessToken
Builds an access token from a raw token.
51 52 53 |
# File 'lib/padlock_auth/token/strategy.rb', line 51 def build_access_token(raw_token) PadlockAuth::Token::AccessToken.new(raw_token, secret_key) end |
#build_access_token_from_credentials(_username, password) ⇒ PadlockAuth::Token::AccessToken
Builds an access token from username and password credentials.
Only the password is required for this strategy, so the username is ignored.
65 66 67 |
# File 'lib/padlock_auth/token/strategy.rb', line 65 def build_access_token_from_credentials(_username, password) PadlockAuth::Token::AccessToken.new(password, secret_key) 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 the builder to validate the configuration.
75 76 77 |
# File 'lib/padlock_auth/token/strategy.rb', line 75 def validate! raise ArgumentError, "secret_key is required" unless secret_key.present? end |