本文整理汇总了Python中tastypie.authentication.MultiAuthentication.get_identifier方法的典型用法代码示例。如果您正苦于以下问题:Python MultiAuthentication.get_identifier方法的具体用法?Python MultiAuthentication.get_identifier怎么用?Python MultiAuthentication.get_identifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.authentication.MultiAuthentication
的用法示例。
在下文中一共展示了MultiAuthentication.get_identifier方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_apikey_and_basic_auth
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_apikey_and_basic_auth(self):
auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
request = HttpRequest()
john_doe = User.objects.get(username='johndoe')
# No API Key or HTTP Basic auth details should fail.
self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)
# Basic Auth still returns appropriately.
self.assertEqual(auth.is_authenticated(request)['WWW-Authenticate'], 'Basic Realm="django-tastypie"')
# API Key Auth works.
request = HttpRequest()
request.GET['username'] = 'johndoe'
request.GET['api_key'] = john_doe.api_key.key
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), 'johndoe')
# Basic Auth works.
request = HttpRequest()
john_doe = User.objects.get(username='johndoe')
john_doe.set_password('pass')
john_doe.save()
request.META['HTTP_AUTHORIZATION'] = 'Basic %s' % base64.b64encode('johndoe:pass'.encode('utf-8')).decode('utf-8')
self.assertEqual(auth.is_authenticated(request), True)
示例2: test_multiauth_apikey_and_basic_auth__api_key_works_in_header
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_multiauth_apikey_and_basic_auth__api_key_works_in_header(self):
auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
request = HttpRequest()
john_doe = User.objects.get(username='johndoe')
request.META['HTTP_AUTHORIZATION'] = 'ApiKey %s:%s' % (john_doe.username, john_doe.api_key.key,)
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), john_doe.username)
示例3: test_multiauth_apikey_and_basic_auth__api_key_works_in_query
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_multiauth_apikey_and_basic_auth__api_key_works_in_query(self):
auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
request = HttpRequest()
john_doe = User.objects.get(username='johndoe')
request.GET['username'] = john_doe.username
request.GET['api_key'] = john_doe.api_key.key
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), john_doe.username)
示例4: test_multiauth_apikey_and_basic_auth__basic_auth_works
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_multiauth_apikey_and_basic_auth__basic_auth_works(self):
auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
request = HttpRequest()
john_doe = User.objects.get(username='johndoe')
john_doe.set_password('pass')
john_doe.save()
request.META['HTTP_AUTHORIZATION'] = 'Basic %s' % base64.b64encode('johndoe:pass'.encode('utf-8')).decode('utf-8')
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), john_doe.username)
示例5: test_multiauth_apikey_and_basic_auth__api_key_works_in_header__space_in_username
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_multiauth_apikey_and_basic_auth__api_key_works_in_header__space_in_username(self):
auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
request = HttpRequest()
john_doe = User.objects.get(username="johndoe")
john_doe.username = "john doe"
john_doe.save()
request.META["HTTP_AUTHORIZATION"] = "ApiKey %s:%s" % (john_doe.username, john_doe.api_key.key)
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), john_doe.username)
示例6: test_apikey_and_authentication
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_apikey_and_authentication(self):
auth = MultiAuthentication(ApiKeyAuthentication(), Authentication())
request = HttpRequest()
john_doe = User.objects.get(username='johndoe')
# No username/api_key details should pass.
self.assertEqual(auth.is_authenticated(request), True)
# The identifier should be the basic auth stock.
self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')
# Wrong username details.
request = HttpRequest()
request.GET['username'] = 'foo'
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')
# No api_key.
request = HttpRequest()
request.GET['username'] = 'daniel'
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')
# Wrong user/api_key.
request = HttpRequest()
request.GET['username'] = 'daniel'
request.GET['api_key'] = 'foo'
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')
request = HttpRequest()
request.GET['username'] = 'johndoe'
request.GET['api_key'] = john_doe.api_key.key
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), john_doe.username)
示例7: test_multiauth_apikey_and_basic_auth__basic_auth_works
# 需要导入模块: from tastypie.authentication import MultiAuthentication [as 别名]
# 或者: from tastypie.authentication.MultiAuthentication import get_identifier [as 别名]
def test_multiauth_apikey_and_basic_auth__basic_auth_works(self):
auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
request = HttpRequest()
john_doe = User.objects.get(username="johndoe")
john_doe.set_password("pass")
john_doe.save()
request.META["HTTP_AUTHORIZATION"] = "Basic %s" % base64.b64encode("johndoe:pass".encode("utf-8")).decode(
"utf-8"
)
self.assertEqual(auth.is_authenticated(request), True)
self.assertEqual(auth.get_identifier(request), john_doe.username)