(oidc) add django-oauth-toolkit w/ configuration

This allows to use `people` as an identity provider using
OIDC and local users.
This commit is partial, because it does not manage a way to
create "local" users and the login page is the admin one, which
can't be used for non staff users or login with email.
This commit is contained in:
Quentin BEY
2025-01-14 11:43:42 +01:00
committed by BEY Quentin
parent 8faa049046
commit db6cdadd72
30 changed files with 1505 additions and 38 deletions

View File

@@ -0,0 +1,48 @@
"""
Serializers for the mailbox_oauth2 app.
"""
from django.contrib.auth import authenticate
from rest_framework import serializers
class LoginSerializer(serializers.Serializer):
"""
Serializer for user login authentication.
Validates the email and password fields required for user authentication.
"""
email = serializers.EmailField(
help_text="User's email address for authentication",
required=True,
)
password = serializers.CharField(
write_only=True,
help_text="User's password for authentication",
required=True,
)
def create(self, validated_data):
"""Do not allow creating instances from this serializer."""
raise RuntimeError("LoginSerializer does not support create method")
def update(self, instance, validated_data):
"""Do not allow updating instances from this serializer."""
raise RuntimeError("LoginSerializer does not support update method")
def validate(self, attrs):
"""
Validate the email and password fields.
"""
email = attrs.get("email")
password = attrs.get("password")
if not (email and password):
raise serializers.ValidationError('Must include "email" and "password"')
attrs["user"] = authenticate(
self.context["request"], email=email, password=password
)
return attrs