Add OpenID API

This commit is contained in:
Jens Langhammer 2018-11-24 22:24:11 +01:00
parent d0a7bf5ecc
commit f298c42adc
No known key found for this signature in database
GPG Key ID: BEBC05297D92821B
5 changed files with 37 additions and 2 deletions

View File

@ -2,6 +2,7 @@
from django.apps import AppConfig
class PassbookAPIConfig(AppConfig):
"""passbook API Config"""

View File

@ -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))
]

22
passbook/api/v1/openid.py Normal file
View File

@ -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)

View File

@ -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')
]

View File

@ -1 +0,0 @@
from rest_framework.viewsets import ViewSet