-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLACEHOLDER: Add feide authentication endpoints
- Loading branch information
Showing
6 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.conf import settings | ||
from django.urls import reverse | ||
from rest_framework import viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from authlib.integrations.django_client import OAuth | ||
from icecream import ic | ||
from structlog import get_logger | ||
|
||
from lego.apps.users.models import User | ||
from lego.apps.users.serializers.users import PublicUserSerializer | ||
|
||
log = get_logger() | ||
|
||
oauth = OAuth() | ||
oauth.register( | ||
name="feide", | ||
client_id=settings.FEIDE_OIDC_CLIENT_ID, | ||
client_secret=settings.FEIDE_OIDC_CLIENT_SECRET, | ||
server_metadata_url=settings.FEIDE_OIDC_CONFIGURATION_ENDPOINT, | ||
client_kwargs={"scope": "openid"}, | ||
) | ||
|
||
|
||
class OIDCViewSet(viewsets.GenericViewSet): | ||
|
||
permission_classes = (IsAuthenticated,) | ||
|
||
@action(detail=False, methods=["GET"]) | ||
def authorize(self, request): | ||
redirect_uri = request.build_absolute_uri(reverse("api:v1:oidc-callback")) | ||
return oauth.feide.authorize_redirect(request, redirect_uri) | ||
|
||
@action(detail=False, methods=["GET"]) | ||
def callback(self, request): | ||
token = oauth.feide.authorize_access_token(request) | ||
ic(token) | ||
return request.redirect(settings.FRONTEND_URL) | ||
|
||
def get_queryset(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,4 @@ Pygments==2.14.0 | |
Markdown==3.4.1 | ||
coreapi==2.3.3 | ||
aiosmtpd==1.4.4.post2 | ||
Authlib==1.2.0 |