Class: PadlockAuth::Token::Strategy

Inherits:
AbstractStrategy show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Config::Option

extended, option

Methods inherited from AbstractStrategy

#build_forbidden_token_response, #build_invalid_token_response

Instance Attribute Details

#secret_keyString (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.

Examples:

PadlockAuth::Token::Strategy.build do
  secret_key "my_secret_key"
end

Yields:

  • block to configure the strategy

See Also:



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.

Raises:

  • (ArgumentError)

    If the secret key is missing



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