File tree Expand file tree Collapse file tree 6 files changed +15
-16
lines changed
Expand file tree Collapse file tree 6 files changed +15
-16
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,9 @@ have an authority field matching that of the user
5757 control by user scopes
5858- Backends: Replace reference to a JSON column in ClickHouse with
5959 function calls on the String column [ BC]
60- - API: Variable ` RUNSERVER_AUTH_BACKEND ` becomes ` RUNSERVER_AUTH_BACKENDS ` , and
61- multiple authentication methods are supported simultaneously
60+ - API: Variable ` RALPH_RUNSERVER_AUTH_BACKEND ` becomes
61+ ` RALPH_RUNSERVER_AUTH_BACKENDS ` , and multiple authentication methods are
62+ supported simultaneously
6263
6364### Fixed
6465
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ $ curl --user
[email protected] :PASSWORD http://localhost:8100/whoami
109109Ralph LRS API server supports OpenID Connect (OIDC) on top of OAuth 2.0 for authentication and authorization.
110110
111111
112- To enable OIDC auth, you should modify the ` RALPH_RUNSERVER_AUTH_BACKENDS ` environment variable by adding (or replacing) ` oidc ` :
112+ To enable OIDC auth, you should modify the ` RALPH_RUNSERVER_AUTH_BACKENDS ` environment variable by adding (or replacing by ) ` oidc ` :
113113``` bash
114114RALPH_RUNSERVER_AUTH_BACKENDS=basic,oidc
115115```
Original file line number Diff line number Diff line change 11"""Main module for Ralph's LRS API authentication."""
22
3+ from typing import Annotated
4+
35from fastapi import Depends , HTTPException , status
46from fastapi .security import SecurityScopes
57
8+ from ralph .api .auth .basic import AuthenticatedUser
69from ralph .api .auth .basic import get_basic_auth_user
710from ralph .api .auth .oidc import get_oidc_user
811from ralph .conf import AuthBackend , settings
912
1013
1114def get_authenticated_user (
1215 security_scopes : SecurityScopes = SecurityScopes ([]),
13- basic_auth_user = Depends (get_basic_auth_user ),
14- oidc_auth_user = Depends (get_oidc_user ),
15- ):
16+ basic_auth_user : Optional [ AuthenticatedUser ] = Depends (get_basic_auth_user ),
17+ oidc_auth_user : Optional [ AuthenticatedUser ] = Depends (get_oidc_user ),
18+ ) -> AuthenticatedUser :
1619 """Authenticate user with any allowed method, using credentials in the header."""
1720 if AuthBackend .BASIC not in settings .RUNSERVER_AUTH_BACKENDS :
1821 basic_auth_user = None
1922 if AuthBackend .OIDC not in settings .RUNSERVER_AUTH_BACKENDS :
2023 oidc_auth_user = None
2124
22- if basic_auth_user is not None :
25+ if basic_auth_user :
2326 user = basic_auth_user
2427 auth_method = "Basic"
25- elif oidc_auth_user is not None :
28+ elif oidc_auth_user :
2629 user = oidc_auth_user
2730 auth_method = "Bearer"
2831 else :
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ def discover_provider(base_url: AnyUrl) -> Dict:
6666 )
6767 raise HTTPException (
6868 status_code = status .HTTP_401_UNAUTHORIZED ,
69- detail = "Could not validate credentials ABU" ,
69+ detail = "Could not validate credentials" , # TODO: this is not tested
7070 headers = {"WWW-Authenticate" : "Bearer" },
7171 ) from exc
7272
@@ -88,7 +88,7 @@ def get_public_keys(jwks_uri: AnyUrl) -> Dict:
8888 )
8989 raise HTTPException (
9090 status_code = status .HTTP_401_UNAUTHORIZED ,
91- detail = "Could not validate credentials ABA" ,
91+ detail = "Could not validate credentials" , # TODO: this is not tested
9292 headers = {"WWW-Authenticate" : "Bearer" },
9393 ) from exc
9494
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ class AuthBackends(str):
145145
146146 @classmethod
147147 def __get_validators__ (cls ): # noqa: D105
148- """Checks whether the value is a comma separated string or a tuple representing
148+ """Check whether the value is a comma separated string or a tuple representing
149149 an AuthBackend."""
150150
151151 def validate (
Original file line number Diff line number Diff line change 99from ralph .conf import CommaSeparatedTuple , Settings , settings
1010from ralph .exceptions import ConfigurationException
1111
12- # import os
13- # def test_env_dist(fs, monkeypatch):
14- # fs.create_file(".env", contents=os.read("../.env.dist"))
15- # Settings()
16-
1712
1813def test_conf_settings_field_value_priority (fs , monkeypatch ):
1914 """Test that the Settings object field values are defined in the following
You can’t perform that action at this time.
0 commit comments