2016-11-17 6 views
2

Alexaと他のサードパーティのAPIを統合するために、バックエンドにDjango OAuthを実装しようとしています。サイト(http://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial.html)のチュートリアルに従っていますが、これまでに逃げてきたセキュリティに関する質問にぶつかってきました。Django OAuth Toolkitのセキュリティを確保する

https://<oursite.com>/o/applicationsにアクセスできるセキュリティ上の懸念はありますか?その場合、ユーザーがこれらのビューにアクセスできないようにするためにはどのような手順をとる必要がありますか?

SO特に有用ではなかったにのみ関連質問:

Secure creation of new applications in Django OAuth Toolkit

Disable or restrict /o/applications (django rest framework, oauth2)

答えて

2

私は同じようなことをやっている、と私は誰もが見ることができるというセキュリティ上の問題であると考えています/ o/applications - 私が知る限り、そのページは本番用ページではなく、開発用ユーティリティであることを意味します。実際には、the django-oauth-toolkit documentationには、ビューへのアクセスが制限されたコード例があります。

from django.conf.urls import url 
import oauth2_provider.views as oauth2_views 
from django.conf import settings 
from .views import ApiEndpoint 

# OAuth2 provider endpoints 
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 Application Management endpoints 
    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 Token Management endpoints 
    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 = [ 
    # OAuth 2 endpoints: 
    url(r'^o/', include(oauth2_endpoint_views, namespace="oauth2_provider")), 

    url(r'^admin/', include(admin.site.urls)), 
    url(r'^api/hello', ApiEndpoint.as_view()), # an example resource endpoint 
] 

revoke token view is part of the RFCが必要です。私は、AuthorizationView、TokenView、およびRevokeTokenViewだけを含む、私のアプリで同様のアプローチを取った。

希望に役立ちます!

0
from django.contrib.auth.decorators import user_passes_test 

def is_super(user): 
    return user.is_superuser and user.is_active 

... 
    url(r'^applications/$', user_passes_test(is_super)(oauth2_views.ApplicationList.as_view()), name="list"), 
... 
関連する問題