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


Python api_settings.DEFAULT_AUTHENTICATION_CLASSES屬性代碼示例

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


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

示例1: get_docs_view

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def get_docs_view(
        title=None, description=None, schema_url=None, public=True,
        patterns=None, generator_class=SchemaGenerator,
        authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
        permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
        renderer_classes=None):

    if renderer_classes is None:
        renderer_classes = [DocumentationRenderer, CoreJSONRenderer]

    return get_schema_view(
        title=title,
        url=schema_url,
        description=description,
        renderer_classes=renderer_classes,
        public=public,
        patterns=patterns,
        generator_class=generator_class,
        authentication_classes=authentication_classes,
        permission_classes=permission_classes,
    ) 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:23,代碼來源:documentation.py

示例2: get_schemajs_view

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def get_schemajs_view(
        title=None, description=None, schema_url=None, public=True,
        patterns=None, generator_class=SchemaGenerator,
        authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
        permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
    renderer_classes = [SchemaJSRenderer]

    return get_schema_view(
        title=title,
        url=schema_url,
        description=description,
        renderer_classes=renderer_classes,
        public=public,
        patterns=patterns,
        generator_class=generator_class,
        authentication_classes=authentication_classes,
        permission_classes=permission_classes,
    ) 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:20,代碼來源:documentation.py

示例3: get_schema_view

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def get_schema_view(
        title=None, url=None, description=None, urlconf=None, renderer_classes=None,
        public=False, patterns=None, generator_class=SchemaGenerator,
        authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
        permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
    """
    Return a schema view.
    """
    # Avoid import cycle on APIView
    from .views import SchemaView
    generator = generator_class(
        title=title, url=url, description=description,
        urlconf=urlconf, patterns=patterns,
    )
    return SchemaView.as_view(
        renderer_classes=renderer_classes,
        schema_generator=generator,
        public=public,
        authentication_classes=authentication_classes,
        permission_classes=permission_classes,
    ) 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:23,代碼來源:__init__.py

示例4: _is_auth_token_manager_auth_class_enabled

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def _is_auth_token_manager_auth_class_enabled() -> bool:
    auth_token_manager = _get_auth_token_manager()
    auth_cls = auth_token_manager.get_authentication_class()
    return any(
        issubclass(cls, auth_cls)
        for cls in api_settings.DEFAULT_AUTHENTICATION_CLASSES
    ) 
開發者ID:apragacz,項目名稱:django-rest-registration,代碼行數:9,代碼來源:checks.py

示例5: as_view

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def as_view(cls, *args, **kwargs):
        view = super(AuthenticatedGraphQLView, cls).as_view(*args, **kwargs)
        view = permission_classes((IsAuthenticated,))(view)
        view = authentication_classes(api_settings.DEFAULT_AUTHENTICATION_CLASSES)(view)
        view = throttle_classes(api_settings.DEFAULT_THROTTLE_CLASSES)(view)
        view = api_view(["GET", "POST"])(view)
        view = csrf_exempt(view)

        return view 
開發者ID:eamigo86,項目名稱:graphene-django-extras,代碼行數:11,代碼來源:views.py

示例6: test_configuration_restframework_htaccess

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def test_configuration_restframework_htaccess(self, _mock_list):
        """The search API endpoint should work behind an htaccess."""
        # First, check that API calls were broken with the default DRF configuration
        # What was happening is that DRF defines Basic Authentication as a fallback by default
        # and our query has a basic auth header with the username and password of the htaccess
        # defined in nginx. Django was trying to authenticate a user with these credentials,
        # which of course failed.
        with override_settings(
            REST_FRAMEWORK={
                **settings.REST_FRAMEWORK,
                "DEFAULT_AUTHENTICATION_CLASSES": DEFAULTS[
                    "DEFAULT_AUTHENTICATION_CLASSES"
                ],
            }
        ):
            authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES

        # The authentication classes are loaded before settings are overriden so we need
        # to mock them on the APIView
        with mock.patch(
            "rest_framework.views.APIView.authentication_classes",
            new_callable=mock.PropertyMock,
            return_value=authentication_classes,
        ):
            response = self.client.get(
                "/api/v1.0/courses/",
                HTTP_AUTHORIZATION="Basic dXNlcm5hbWU6cGFzc3dvcmQ=",
            )
        self.assertEqual(response.status_code, 403)

        # Check that the project configuration solves it
        response = self.client.get(
            "/api/v1.0/courses/", HTTP_AUTHORIZATION="Basic dXNlcm5hbWU6cGFzc3dvcmQ="
        )
        self.assertEqual(response.status_code, 200) 
開發者ID:openfun,項目名稱:richie,代碼行數:37,代碼來源:test_settings.py

示例7: superuser_or_username_matches_prefix

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def superuser_or_username_matches_prefix(private_file):
    """
    You can create a custom function, and use that instead. The function
    receives a private_storate.models.PrivateFile object, which has the
    following fields:

        request: the Django request.
        storage: the storage engine used to retrieve the file.
        relative_name: the file name in the storage.
        full_path: the full file system path.
        exists(): whether the file exists.
        content_type: the HTTP content type.

    (See https://github.com/edoburu/django-private-storage)
    """

    user = private_file.request.user

    if not user.is_authenticated:
        # Try all the DRF authentication methods before giving up
        request = DRFRequest(
            private_file.request,
            authenticators=[
                auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES
            ]
        )
        user = request.user
        if not user.is_authenticated:
            return False

    if user.is_superuser:
        return True

    if private_file.relative_name.startswith(
        '{}/'.format(user.username)
    ):
        return True

    return False 
開發者ID:kobotoolbox,項目名稱:kpi,代碼行數:41,代碼來源:private_storage.py

示例8: include_docs_urls

# 需要導入模塊: from rest_framework.settings import api_settings [as 別名]
# 或者: from rest_framework.settings.api_settings import DEFAULT_AUTHENTICATION_CLASSES [as 別名]
def include_docs_urls(
        title=None, description=None, schema_url=None, public=True,
        patterns=None, generator_class=SchemaGenerator,
        authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
        permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
        renderer_classes=None):
    docs_view = get_docs_view(
        title=title,
        description=description,
        schema_url=schema_url,
        public=public,
        patterns=patterns,
        generator_class=generator_class,
        authentication_classes=authentication_classes,
        renderer_classes=renderer_classes,
        permission_classes=permission_classes,
    )
    schema_js_view = get_schemajs_view(
        title=title,
        description=description,
        schema_url=schema_url,
        public=public,
        patterns=patterns,
        generator_class=generator_class,
        authentication_classes=authentication_classes,
        permission_classes=permission_classes,
    )
    urls = [
        url(r'^$', docs_view, name='docs-index'),
        url(r'^schema.js$', schema_js_view, name='schema-js')
    ]
    return include((urls, 'api-docs'), namespace='api-docs') 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:34,代碼來源:documentation.py


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