-
Notifications
You must be signed in to change notification settings - Fork 22
✨(back) integrate resource server API #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
2a19602 to
238a83c
Compare
0758b5f to
75cf0c7
Compare
33ca843 to
32dd759
Compare
| ): | ||
| return False | ||
|
|
||
| # When used as a resource server, the request has a token audience |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment needs an update and so the docstring (class & method)
| try: | ||
| payload = jwt.decode( | ||
| token, settings.JWT_SECRET_KEY, algorithms=[settings.JWT_ALGORITHM] | ||
| ) | ||
| except jwt.InvalidTokenError as e: | ||
| logger.error("Invalid JWT token: %s", e) | ||
| return None | ||
|
|
||
| if not payload.get("sub") or not payload.get("email"): | ||
| logger.warning("Invalid JWT token. Missing 'sub' or 'email' in payload") | ||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be carreful here, because the OIDC authentication can also use the "Bearer" format, and provide a JWT (the OIDC access token can be a JWT), so you will log error and warning even for valid OIDC authentication.
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class JWTAuthentication(authentication.BaseAuthentication): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may add a authenticate_header method to return a 401 instead of a 403 when no authentication is provided.
a820d78 to
24a7a15
Compare
We expose now an external API. This external API can be used using a resource server authentication. The urls are prefixed with /external_api/v1.0 and for now the viewsets available are the Item and ItemAccess.
The mozilla OIDCAuthentication backend was configured in the DRF settings but not used. We have to remove it.
The external_api prefix must be managed by an ingress to use the correct backend, the impress-backend one.
We want to allow temporarily the connection of the external API using a JWT token with a simmetric key. This simmetric key must be used with the system allowed to request drive.
By introducing an other authentication class the status code has changed from 401 to 403. All new code added since june must be updated.
24a7a15 to
105dbd1
Compare
Purpose
Expose endpoints for external api. This endpoints will allow to work on the
itemanditemAccessresources.The external apis are available with these urls:
To authenticate to this API, the request must have a Bearer token provided by your OIDC provider when the user is connected. The authentication will introspect the given token by fetching an introspection endpoint provided by your OIDC provider.
To configure your instance, you can follow this documentation: https://github.com/suitenumerique/django-lasuite/blob/main/documentation/how-to-use-oidc-resource-server-backend.md