Skip to content

Commit d62f720

Browse files
committed
minor fixing
1 parent dc07d0b commit d62f720

File tree

6 files changed

+15
-16
lines changed

6 files changed

+15
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ $ curl --user [email protected]:PASSWORD http://localhost:8100/whoami
109109
Ralph 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
114114
RALPH_RUNSERVER_AUTH_BACKENDS=basic,oidc
115115
```

src/ralph/api/auth/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
"""Main module for Ralph's LRS API authentication."""
22

3+
from typing import Annotated
4+
35
from fastapi import Depends, HTTPException, status
46
from fastapi.security import SecurityScopes
57

8+
from ralph.api.auth.basic import AuthenticatedUser
69
from ralph.api.auth.basic import get_basic_auth_user
710
from ralph.api.auth.oidc import get_oidc_user
811
from ralph.conf import AuthBackend, settings
912

1013

1114
def 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:

src/ralph/api/auth/oidc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

src/ralph/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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(

tests/test_conf.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
from ralph.conf import CommaSeparatedTuple, Settings, settings
1010
from 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

1813
def test_conf_settings_field_value_priority(fs, monkeypatch):
1914
"""Test that the Settings object field values are defined in the following

0 commit comments

Comments
 (0)