1010from authlib .integrations .flask_oauth2 import ResourceProtector
1111from authlib .oauth2 .rfc6750 import BearerTokenValidator
1212from ..auth .validation import Auth0JWTBearerTokenValidator
13- from ..utils .config_loader import get_config , get_config_value
13+ from ..utils .config_loader import get_config_value
14+
15+ ANALYTICS_READ_SCOPE = "read:calculate-analytics"
1416
1517
1618class StaticBearerToken :
@@ -33,15 +35,16 @@ def get_scope(self) -> str:
3335class StaticBearerTokenValidator (BearerTokenValidator ):
3436 """Accept a single configured bearer token for test environments."""
3537
36- def __init__ (self , expected_token : str ):
38+ def __init__ (self , expected_token : str , scopes : str | None = "" ):
3739 super ().__init__ ()
3840 self .expected_token = expected_token
41+ self .scopes = scopes or ""
3942
4043 def authenticate_token (
4144 self , token_string : Optional [str ]
4245 ) -> Optional [StaticBearerToken ]:
4346 if token_string == self .expected_token :
44- return StaticBearerToken (token_string )
47+ return StaticBearerToken (token_string , scope = self . scopes )
4548 return None
4649
4750
@@ -98,6 +101,9 @@ def _setup_authentication(self) -> None:
98101 self ._auth_enabled = get_config_value ("auth.enabled" , False )
99102 app_environment = get_config_value ("app.environment" , "" )
100103 auth0_test_token = get_config_value ("auth.auth0.test_token" , "" )
104+ auth0_test_token_scopes = get_config_value (
105+ "auth.auth0.test_token_scopes" , ""
106+ )
101107
102108 # Get Auth0 configuration values
103109 auth0_address = get_config_value ("auth.auth0.address" , "" )
@@ -108,7 +114,9 @@ def _setup_authentication(self) -> None:
108114 if app_environment == "test_with_auth" and auth0_test_token :
109115 resource_protector = ResourceProtector ()
110116 resource_protector .register_token_validator (
111- StaticBearerTokenValidator (auth0_test_token )
117+ StaticBearerTokenValidator (
118+ auth0_test_token , auth0_test_token_scopes
119+ )
112120 )
113121 self ._decorator = resource_protector
114122 elif auth0_address and auth0_audience :
0 commit comments