Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1338 | OID To Django Token API
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Sep 30, 2022
1 parent 96e35fe commit 2b7c200
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

urlpatterns = [
re_path(r'^$', views.UserListView.as_view(), name='userprofile-list'),
path('api-token/', views.TokenExchangeView.as_view(), name='user-oid-django-token-exchange'),
path('oidc/code-exchange/', views.OIDCodeExchangeView.as_view(), name='user-oid-code-exchange'),
path('oidc/logout/', views.UserOIDLogoutView.as_view(), name='user-logout'),
path('login/', views.TokenAuthenticationView.as_view(), name='user-login'),
Expand Down
8 changes: 8 additions & 0 deletions core/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def post(self, request, **kwargs): # pylint: disable=unused-argument
return Response(result)


class TokenExchangeView(APIView):
permission_classes = (IsAuthenticated, )

@staticmethod
def get(request):
return Response(dict(token=request.user.get_token()))


class TokenAuthenticationView(ObtainAuthToken):
"""Implementation of ObtainAuthToken with last_login update"""

Expand Down

0 comments on commit 2b7c200

Please sign in to comment.