Consider implementing function views as viewsets to allow use with DRF router
Related issue on the DRF repository - doesn't seem like the maintainer has interest in extending routers to handle individual views: https://github.com/encode/django-rest-framework/issues/3931
As is, can't register either of the token endpoints with a DRF router because the router classes only accept viewsets:
# instead of..
urlpatterns = [
path('api/token/', OIDCTokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
]
# Something like this is not possible
router = routers.DefaultRouter()
router.register(r'api/token/', OIDCTokenObtainPairView.as_view(), basename='token_obtain')
router.register(r'api/token/refresh/', TokenRefreshView.as_view(), basename='token_refresh'),
urlpatterns = [
path('', include(router.urls)),
]
A benefit we would get out of using a router is the browsable api it provides, potential downside is the odd way we'll have to inherit and route verbs on the viewset: (from: https://github.com/encode/django-rest-framework/issues/3931#issuecomment-538030520)
class AuthTokenViewSet(ObtainAuthToken, ViewSet):
def create(self, request, *args, **kwargs):
# note that we need to call super here, so that we call `ObtainAuthToken.post`
# instead of the `post` method set by `ViewSet.as_view()`
return super().post(request, *args, **kwargs)