當前位置: 首頁>>代碼示例>>Python>>正文


Python authentication.SessionAuthentication方法代碼示例

本文整理匯總了Python中rest_framework.authentication.SessionAuthentication方法的典型用法代碼示例。如果您正苦於以下問題:Python authentication.SessionAuthentication方法的具體用法?Python authentication.SessionAuthentication怎麽用?Python authentication.SessionAuthentication使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.authentication的用法示例。


在下文中一共展示了authentication.SessionAuthentication方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_schema_view

# 需要導入模塊: from rest_framework import authentication [as 別名]
# 或者: from rest_framework.authentication import SessionAuthentication [as 別名]
def get_schema_view(self):
        view = get_schema_view(
            openapi.Info(
                title="Django Bananas Admin API Schema",
                default_version=BananasVersioning.default_version,
                description="API for django-bananas.js",
                # terms_of_service="https://www.google.com/policies/terms/",
                # license=openapi.License(name="BSD License"),
            ),
            # validators=["flex", "ssv"],
            public=False,
            generator_class=BananasOpenAPISchemaGenerator,
            authentication_classes=(SessionAuthentication,),
            permission_classes=(permissions.AllowAny,),
            patterns=self.urls,
        )
        view.versioning_class = BananasVersioning

        return view 
開發者ID:5monkeys,項目名稱:django-bananas,代碼行數:21,代碼來源:yasg.py

示例2: has_permission

# 需要導入模塊: from rest_framework import authentication [as 別名]
# 或者: from rest_framework.authentication import SessionAuthentication [as 別名]
def has_permission(self, request, view):
        if not request.user or not request.user.is_authenticated:
            # must be authenticated one way or another
            return False

        authenticator = request.successful_authenticator
        required_permissions = view.consumer_permissions

        if isinstance(authenticator, authentication.SessionAuthentication):
            # CAS authenticated: the world is your oyster
            return True

        elif isinstance(authenticator, OAuthAuthentication):
            # OAuth authenticated: check that the consumer is allowed to do these things

            # re-find the Token, since it isn't stashed in the request
            # could be avoided if: http://code.larlet.fr/django-oauth-plus/issue/40/set-requestconsumer-and-requesttoken-to
            oauth_req = get_oauth_request(request)
            token = get_object_or_404(Token, key=oauth_req['oauth_token'], consumer__key=oauth_req['oauth_consumer_key'])

            # consumer must have asked for all of the permissions being used
            allowed_perms = ConsumerInfo.allowed_permissions(token)
            return set(required_permissions) <= set(allowed_perms)

        else:
            raise ValueError("Unknown authentication method.") 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:28,代碼來源:rest.py


注:本文中的rest_framework.authentication.SessionAuthentication方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。