Add OpenID API
This commit is contained in:
parent
d0a7bf5ecc
commit
f298c42adc
|
@ -2,6 +2,7 @@
|
|||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class PassbookAPIConfig(AppConfig):
|
||||
"""passbook API Config"""
|
||||
|
||||
|
|
|
@ -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))
|
||||
]
|
||||
|
|
|
@ -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)
|
|
@ -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')
|
||||
]
|
|
@ -1 +0,0 @@
|
|||
from rest_framework.viewsets import ViewSet
|
Reference in New Issue