本文整理汇总了Python中tastypie.authentication.OAuthAuthentication类的典型用法代码示例。如果您正苦于以下问题:Python OAuthAuthentication类的具体用法?Python OAuthAuthentication怎么用?Python OAuthAuthentication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OAuthAuthentication类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_check_active_true
def test_check_active_true(self):
auth = OAuthAuthentication()
# No username/api_key details should fail.
self.request.REQUEST = self.request.GET = {
'oauth_consumer_key': '123',
'oauth_nonce': 'abc',
'oauth_signature': '&',
'oauth_signature_method': 'PLAINTEXT',
'oauth_timestamp': str(int(time.time())),
'oauth_token': 'bar',
}
self.request.META['Authorization'] = 'OAuth ' + ','.join([key+'='+value for key, value in self.request.REQUEST.items()])
resp = auth.is_authenticated(self.request)
self.assertFalse(resp)
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:15,代码来源:authentication.py
示例2: test_check_active_true
def test_check_active_true(self):
auth = OAuthAuthentication()
# No username/api_key details should fail.
self.request.REQUEST = self.request.GET = {
"oauth_consumer_key": "123",
"oauth_nonce": "abc",
"oauth_signature": "&",
"oauth_signature_method": "PLAINTEXT",
"oauth_timestamp": str(int(time.time())),
"oauth_token": "bar",
}
self.request.META["Authorization"] = "OAuth " + ",".join(
[key + "=" + value for key, value in self.request.REQUEST.items()]
)
resp = auth.is_authenticated(self.request)
self.assertFalse(resp)
开发者ID:mattbriancon,项目名称:django-tastypie,代码行数:17,代码来源:authentication.py
示例3: MultiAuthentication
class MultiAuthentication(object):
"""
A custom authentication backend that supports anonymous access, OAuth authentication, and API key authentication.
"""
def __init__(self, **kwargs):
super(MultiAuthentication, self).__init__(**kwargs)
self.ApiKeyBackend = ApiKeyAuthentication()
self.OAuthBackend = OAuthAuthentication()
def is_authenticated(self, request, **kwargs):
"""
Identifies if the user is authenticated to continue or not.
Should return either ``True`` if allowed, ``False`` if not or an
``HttpResponse`` if you need something custom.
"""
if self.ApiKeyBackend.is_valid_request(request):
check = self.ApiKeyBackend.is_authenticated(request, **kwargs)
if check is True:
request._authentication_backend = self.ApiKeyBackend
return check
if self.OAuthBackend.is_valid_request(request):
check = self.OAuthBackend.is_authenticated(request, **kwargs)
if check is True:
request._authentication_backend = self.OAuthBackend
return check
else:
# Authenticate the request as the anonymous user
request.user = User.objects.get(id=ANONYMOUS_USER_ID)
return True
def get_identifier(self, request):
"""
Provides a unique string identifier for the requestor.
This implementation returns a combination of IP address and hostname.
"""
try:
return request._authentication_backend.get_identifier(request)
except AttributeError:
return 'nouser'
开发者ID:readingr,项目名称:provenance,代码行数:43,代码来源:auth.py
示例4: test_is_authenticated
def test_is_authenticated(self):
auth = OAuthAuthentication()
# Invalid request.
resp = auth.is_authenticated(self.request)
self.assertEqual(resp.status_code, 401)
# No username/api_key details should fail.
self.request.REQUEST = self.request.GET = {
'oauth_consumer_key': '123',
'oauth_nonce': 'abc',
'oauth_signature': '&',
'oauth_signature_method': 'PLAINTEXT',
'oauth_timestamp': str(int(time.time())),
'oauth_token': 'foo',
}
self.request.META['Authorization'] = 'OAuth ' + ','.join([key+'='+value for key, value in self.request.REQUEST.items()])
resp = auth.is_authenticated(self.request)
self.assertEqual(resp, True)
self.assertEqual(self.request.user.pk, self.user.pk)
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:20,代码来源:authentication.py
示例5: test_is_authenticated
def test_is_authenticated(self):
from oauth_provider.models import Consumer, Token, Resource
auth = OAuthAuthentication()
request = HttpRequest()
request.META['SERVER_NAME'] = 'testsuite'
request.META['SERVER_PORT'] = '8080'
request.REQUEST = request.GET = {}
request.method = "GET"
# Invalid request.
resp = auth.is_authenticated(request)
self.assertEqual(resp.status_code, 401)
# No username/api_key details should fail.
request.REQUEST = request.GET = {
'oauth_consumer_key': '123',
'oauth_nonce': 'abc',
'oauth_signature': '&',
'oauth_signature_method': 'PLAINTEXT',
'oauth_timestamp': str(int(time.time())),
'oauth_token': 'foo',
}
user = User.objects.create_user('daniel', '[email protected]', 'password')
request.META['Authorization'] = 'OAuth ' + ','.join([key+'='+value for key, value in request.REQUEST.items()])
resource, _ = Resource.objects.get_or_create(url='test', defaults={
'name': 'Test Resource'
})
consumer, _ = Consumer.objects.get_or_create(key='123', defaults={
'name': 'Test',
'description': 'Testing...'
})
token, _ = Token.objects.get_or_create(key='foo', token_type=Token.ACCESS, defaults={
'consumer': consumer,
'resource': resource,
'secret': '',
'user': user,
})
resp = auth.is_authenticated(request)
self.assertEqual(resp, True)
self.assertEqual(request.user.pk, user.pk)
开发者ID:Unholster,项目名称:django-tastypie,代码行数:40,代码来源:authentication.py
示例6: test_is_authenticated
def test_is_authenticated(self):
auth = OAuthAuthentication()
# Invalid request.
resp = auth.is_authenticated(self.request)
self.assertEqual(resp.status_code, 401)
# No username/api_key details should fail.
self.request.REQUEST = self.request.GET = {
"oauth_consumer_key": "123",
"oauth_nonce": "abc",
"oauth_signature": "&",
"oauth_signature_method": "PLAINTEXT",
"oauth_timestamp": str(int(time.time())),
"oauth_token": "foo",
}
self.request.META["Authorization"] = "OAuth " + ",".join(
[key + "=" + value for key, value in self.request.REQUEST.items()]
)
resp = auth.is_authenticated(self.request)
self.assertEqual(resp, True)
self.assertEqual(self.request.user.pk, self.user.pk)
开发者ID:mattbriancon,项目名称:django-tastypie,代码行数:22,代码来源:authentication.py
示例7: test_whitelisting
def test_whitelisting(self):
auth = OAuthAuthentication(whitelisted_methods=['a_method'])
# Calling with a whitelisted method_name without credentials should work
self.assertEqual(auth.is_authenticated(self.request, method_name='a_method'), True)
# Calling any other method should require auth
resp = auth.is_authenticated(self.request, method_name='another_method')
self.assertEqual(resp.status_code, 401)
# No username/api_key details should fail.
self.request.REQUEST = self.request.GET = {
'oauth_consumer_key': '123',
'oauth_nonce': 'abc',
'oauth_signature': '&',
'oauth_signature_method': 'PLAINTEXT',
'oauth_timestamp': str(int(time.time())),
'oauth_token': 'foo',
}
self.request.META['Authorization'] = 'OAuth ' + ','.join([key+'='+value for key, value in self.request.REQUEST.items()])
self.assertEqual(auth.is_authenticated(self.request, method_name='a_method'), True)
self.assertEqual(auth.is_authenticated(self.request, method_name='another_method'), True)
开发者ID:YACFirm,项目名称:django-tastypie,代码行数:22,代码来源:authentication.py
示例8: test_is_authenticated
def test_is_authenticated(self):
from oauth_provider.models import Consumer, Token, Resource
auth = OAuthAuthentication()
request = HttpRequest()
request.META["SERVER_NAME"] = "testsuite"
request.META["SERVER_PORT"] = "8080"
request.REQUEST = request.GET = {}
request.method = "GET"
# Invalid request.
resp = auth.is_authenticated(request)
self.assertEqual(resp.status_code, 401)
# No username/api_key details should fail.
request.REQUEST = request.GET = {
"oauth_consumer_key": "123",
"oauth_nonce": "abc",
"oauth_signature": "&",
"oauth_signature_method": "PLAINTEXT",
"oauth_timestamp": str(int(time.time())),
"oauth_token": "foo",
}
user = User.objects.create_user("daniel", "[email protected]", "password")
request.META["Authorization"] = "OAuth " + ",".join(
[key + "=" + value for key, value in request.REQUEST.items()]
)
resource, _ = Resource.objects.get_or_create(url="test", defaults={"name": "Test Resource"})
consumer, _ = Consumer.objects.get_or_create(key="123", defaults={"name": "Test", "description": "Testing..."})
token, _ = Token.objects.get_or_create(
key="foo",
token_type=Token.ACCESS,
defaults={"consumer": consumer, "resource": resource, "secret": "", "user": user},
)
resp = auth.is_authenticated(request)
self.assertEqual(resp, True)
self.assertEqual(request.user.pk, user.pk)
开发者ID:coffindragger,项目名称:django-tastypie,代码行数:37,代码来源:authentication.py
示例9: __init__
def __init__(self, **kwargs):
super(MultiAuthentication, self).__init__(**kwargs)
self.ApiKeyBackend = ApiKeyAuthentication()
self.OAuthBackend = OAuthAuthentication()
开发者ID:readingr,项目名称:provenance,代码行数:4,代码来源:auth.py
注:本文中的tastypie.authentication.OAuthAuthentication类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论