From f298c42adcae7348930053eac094d7e6efab0c29 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 24 Nov 2018 22:24:11 +0100 Subject: [PATCH] Add OpenID API --- passbook/api/apps.py | 1 + passbook/api/urls.py | 7 ++++++- passbook/api/v1/openid.py | 22 ++++++++++++++++++++++ passbook/api/v1/urls.py | 8 ++++++++ passbook/api/v1/views.py | 1 - 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 passbook/api/v1/openid.py delete mode 100644 passbook/api/v1/views.py diff --git a/passbook/api/apps.py b/passbook/api/apps.py index bb23a6df5..d1edbd89d 100644 --- a/passbook/api/apps.py +++ b/passbook/api/apps.py @@ -2,6 +2,7 @@ from django.apps import AppConfig + class PassbookAPIConfig(AppConfig): """passbook API Config""" diff --git a/passbook/api/urls.py b/passbook/api/urls.py index 1e0015469..fa35789b7 100644 --- a/passbook/api/urls.py +++ b/passbook/api/urls.py @@ -1,3 +1,8 @@ """passbook api urls""" +from django.urls import include, path -urlpatterns = [] +from passbook.api.v1.urls import urlpatterns as v1_urls + +urlpatterns = [ + path('v1/', include(v1_urls)) +] diff --git a/passbook/api/v1/openid.py b/passbook/api/v1/openid.py new file mode 100644 index 000000000..a2aa8c2cd --- /dev/null +++ b/passbook/api/v1/openid.py @@ -0,0 +1,22 @@ +"""Passbook v1 OpenID API""" +from django.http import JsonResponse +from django.views import View +from oauth2_provider.views.mixins import ScopedResourceMixin + + +class OpenIDUserInfoView(ScopedResourceMixin, View): + """Passbook v1 OpenID API""" + + required_scopes = ['openid:userinfo'] + + def get(self, request, *args, **kwargs): + """Passbook v1 OpenID API""" + payload = { + 'sub': request.user.pk, + 'name': request.user.get_full_name(), + 'given_name': request.user.first_name, + 'family_name': request.user.last_name, + 'preferred_username': request.user.username + } + + return JsonResponse(payload) diff --git a/passbook/api/v1/urls.py b/passbook/api/v1/urls.py index e69de29bb..78edbd033 100644 --- a/passbook/api/v1/urls.py +++ b/passbook/api/v1/urls.py @@ -0,0 +1,8 @@ +"""Passbook API URLs""" +from django.urls import path + +from passbook.api.v1.openid import OpenIDUserInfoView + +urlpatterns = [ + path('openid/', OpenIDUserInfoView.as_view(), name='openid') +] diff --git a/passbook/api/v1/views.py b/passbook/api/v1/views.py deleted file mode 100644 index 957e59bea..000000000 --- a/passbook/api/v1/views.py +++ /dev/null @@ -1 +0,0 @@ -from rest_framework.viewsets import ViewSet