Class: Spree::Authentication::Strategies::BaseStrategy
- Inherits:
-
Object
- Object
- Spree::Authentication::Strategies::BaseStrategy
- Defined in:
- app/models/spree/authentication/strategies/base_strategy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request_env ⇒ Object
readonly
Returns the value of attribute request_env.
-
#user_class ⇒ Object
readonly
Returns the value of attribute user_class.
Class Method Summary collapse
-
.kind ⇒ Symbol
How a client initiates login with this strategy.
-
.label ⇒ String?
Human-readable provider name for the login button.
Instance Method Summary collapse
-
#authenticate ⇒ Spree::ServiceModule::Result
Returns Result object with user on success.
-
#authorization_url(state:) ⇒ String
Where to send the browser to begin authentication.
-
#callback ⇒ Spree::ServiceModule::Result
Completes a redirect login from the identity provider's callback params.
-
#initialize(params:, request_env:, user_class: nil) ⇒ BaseStrategy
constructor
A new instance of BaseStrategy.
-
#provider ⇒ String
Returns provider identifier (e.g., 'google', 'email').
Constructor Details
#initialize(params:, request_env:, user_class: nil) ⇒ BaseStrategy
Returns a new instance of BaseStrategy.
30 31 32 33 34 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 30 def initialize(params:, request_env:, user_class: nil) @params = params @request_env = request_env @user_class = user_class || Spree.customer_class end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 5 def params @params end |
#request_env ⇒ Object (readonly)
Returns the value of attribute request_env.
5 6 7 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 5 def request_env @request_env end |
#user_class ⇒ Object (readonly)
Returns the value of attribute user_class.
5 6 7 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 5 def user_class @user_class end |
Class Method Details
.kind ⇒ Symbol
How a client initiates login with this strategy.
:password — the client posts credentials to the auth endpoint.
:redirect — the client sends the browser to the identity provider,
which returns through the OAuth callback.
Defaults to :password so strategies written before provider
discovery existed keep describing themselves correctly.
17 18 19 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 17 def kind :password end |
.label ⇒ String?
Human-readable provider name for the login button. Only meaningful for
:redirect strategies; defaults to nil so password strategies render
their standard form instead of a button.
25 26 27 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 25 def label nil end |
Instance Method Details
#authenticate ⇒ Spree::ServiceModule::Result
Returns Result object with user on success
56 57 58 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 56 def authenticate raise NotImplementedError, 'Subclass must implement #authenticate' end |
#authorization_url(state:) ⇒ String
Where to send the browser to begin authentication. Redirect strategies must implement this; password strategies never call it.
41 42 43 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 41 def (state:) raise NotImplementedError, 'Redirect strategies must implement #authorization_url' end |
#callback ⇒ Spree::ServiceModule::Result
Completes a redirect login from the identity provider's callback params.
Redirect strategies must implement this; password strategies use
#authenticate instead.
50 51 52 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 50 def callback raise NotImplementedError, 'Redirect strategies must implement #callback' end |
#provider ⇒ String
Returns provider identifier (e.g., 'google', 'email')
62 63 64 |
# File 'app/models/spree/authentication/strategies/base_strategy.rb', line 62 def provider raise NotImplementedError, 'Subclass must implement #provider' end |