我正在做类似的事情,我认为任何人都可以看到/o/applications是一个安全问题 - 据我所知,该页面旨在成为开发实用工具,而不是生产页面。事实上,在
django-oauth-toolkit文档中,他们有一个代码示例,其中对视图的访问权限更受限制。
from django.conf.urls import url
import oauth2_provider.views as oauth2_views
from django.conf import settings
from .views import ApiEndpoint
oauth2_endpoint_views = [
url(r'^authorize/$', oauth2_views.AuthorizationView.as_view(), name="authorize"),
url(r'^token/$', oauth2_views.TokenView.as_view(), name="token"),
url(r'^revoke-token/$', oauth2_views.RevokeTokenView.as_view(), name="revoke-token"),
]
if settings.DEBUG:
oauth2_endpoint_views += [
url(r'^applications/$', oauth2_views.ApplicationList.as_view(), name="list"),
url(r'^applications/register/$', oauth2_views.ApplicationRegistration.as_view(), name="register"),
url(r'^applications/(?P<pk>\d+)/$', oauth2_views.ApplicationDetail.as_view(), name="detail"),
url(r'^applications/(?P<pk>\d+)/delete/$', oauth2_views.ApplicationDelete.as_view(), name="delete"),
url(r'^applications/(?P<pk>\d+)/update/$', oauth2_views.ApplicationUpdate.as_view(), name="update"),
]
oauth2_endpoint_views += [
url(r'^authorized-tokens/$', oauth2_views.AuthorizedTokensListView.as_view(), name="authorized-token-list"),
url(r'^authorized-tokens/(?P<pk>\d+)/delete/$', oauth2_views.AuthorizedTokenDeleteView.as_view(),
name="authorized-token-delete"),
]
urlpatterns = [
url(r'^o/', include(oauth2_endpoint_views, namespace="oauth2_provider")),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/hello', ApiEndpoint.as_view()),
]
撤销令牌视图是RFC的一部分,所以这个视图是必需的。在我的应用程序中,我采用了类似的方法,只包括AuthorizationView、TokenView和RevokeTokenView。
希望这有所帮助!