当前位置: 首页>>代码示例>>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;未经允许,请勿转载。