本文整理汇总了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,
)
示例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,
)
示例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,
)
示例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
)
示例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
示例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)
示例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
示例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')