44from typing import TYPE_CHECKING , Any , Protocol , cast
55
66from .backends .utils import get_backend
7- from .exceptions import StrategyMissingBackendError , StrategyMissingFeatureError
7+ from .exceptions import (
8+ SocialAuthImproperlyConfiguredError ,
9+ StrategyMissingBackendError ,
10+ StrategyMissingFeatureError ,
11+ )
812from .pipeline import DEFAULT_AUTH_PIPELINE , DEFAULT_DISCONNECT_PIPELINE
913from .pipeline .utils import partial_load
1014from .store import OpenIdSessionWrapper , OpenIdStore
@@ -53,9 +57,15 @@ def __init__(
5357 storage : type [BaseStorage ] | None = None ,
5458 tpl : type [BaseTemplateStrategy ] | None = None ,
5559 ) -> None :
56- self .storage = storage
60+ self ._storage = storage
5761 self .tpl = (tpl or self .DEFAULT_TEMPLATE_STRATEGY )(self )
5862
63+ @property
64+ def storage (self ) -> type [BaseStorage ]:
65+ if self ._storage is None :
66+ raise StrategyMissingBackendError
67+ return self ._storage
68+
5969 def setting (self , name : str , default = None , backend : BaseAuth | None = None ):
6070 names = [setting_name (name ), name ]
6171 if backend :
@@ -68,13 +78,9 @@ def setting(self, name: str, default=None, backend: BaseAuth | None = None):
6878 return default
6979
7080 def create_user (self , * args , ** kwargs ):
71- if self .storage is None :
72- raise StrategyMissingBackendError
7381 return self .storage .user .create_user (* args , ** kwargs )
7482
7583 def get_user (self , * args , ** kwargs ):
76- if self .storage is None :
77- raise StrategyMissingBackendError
7884 return self .storage .user .get_user (* args , ** kwargs )
7985
8086 def session_setdefault (self , name : str , value ):
@@ -121,8 +127,6 @@ def partial_load(self, token: str) -> PartialMixin | None:
121127 return partial_load (self , token )
122128
123129 def clean_partial_pipeline (self , token ) -> None :
124- if self .storage is None :
125- raise StrategyMissingBackendError
126130 self .storage .partial .destroy (token )
127131 current_token_in_session = self .session_get (PARTIAL_TOKEN_SESSION_NAME )
128132 if current_token_in_session == token :
@@ -158,17 +162,17 @@ def get_language(self) -> str:
158162 def send_email_validation (
159163 self , backend : BaseAuth , email : str , partial_token : str | None = None
160164 ) -> CodeMixin :
161- if self .storage is None :
162- raise StrategyMissingBackendError
163165 email_validation = self .setting ("EMAIL_VALIDATION_FUNCTION" )
166+ if not email_validation :
167+ raise SocialAuthImproperlyConfiguredError (
168+ "EMAIL_VALIDATION_FUNCTION missing"
169+ )
164170 send_email = module_member (email_validation )
165171 code = self .storage .code .make_code (email )
166172 send_email (self , backend , code , partial_token )
167173 return code
168174
169175 def validate_email (self , email : str , code : str ) -> bool :
170- if self .storage is None :
171- raise StrategyMissingBackendError
172176 verification_code = self .storage .code .get_code (code )
173177 if not verification_code or verification_code .code != code :
174178 return False
@@ -193,8 +197,6 @@ def authenticate(
193197 ) -> UserProtocol | HttpResponseProtocol | None :
194198 """Trigger the authentication mechanism tied to the current
195199 framework"""
196- if self .storage is None :
197- raise StrategyMissingBackendError
198200 kwargs ["strategy" ] = self
199201 kwargs ["storage" ] = self .storage
200202 kwargs ["backend" ] = backend
0 commit comments