本文整理汇总了Python中oauth2client.contrib.xsrfutil.validate_token方法的典型用法代码示例。如果您正苦于以下问题:Python xsrfutil.validate_token方法的具体用法?Python xsrfutil.validate_token怎么用?Python xsrfutil.validate_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.contrib.xsrfutil
的用法示例。
在下文中一共展示了xsrfutil.validate_token方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_state_value
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def _parse_state_value(state, user):
"""Parse the value of the 'state' parameter.
Parses the value and validates the XSRF token in the state parameter.
Args:
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.
Raises:
InvalidXsrfTokenError: if the XSRF token is invalid.
Returns:
The redirect URI.
"""
uri, token = state.rsplit(':', 1)
if not xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
raise InvalidXsrfTokenError()
return uri
示例2: _parse_state_value
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def _parse_state_value(state, user):
"""Parse the value of the 'state' parameter.
Parses the value and validates the XSRF token in the state parameter.
Args:
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.
Returns:
The redirect URI, or None if XSRF token is not valid.
"""
uri, token = state.rsplit(':', 1)
if xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
return uri
else:
return None
示例3: test_token_length_differs_from_generated
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_token_length_differs_from_generated(self):
token_time = 123456789
# Make sure it isn't too old.
curr_time = token_time + xsrfutil.DEFAULT_TIMEOUT_SECS - 1
key = object()
user_id = object()
action_id = object()
token = base64.b64encode(_helpers._to_bytes(str(token_time)))
generated_token = b'a'
# Make sure the token length comparison will fail.
self.assertNotEqual(len(token), len(generated_token))
with mock.patch('oauth2client.contrib.xsrfutil.generate_token',
return_value=generated_token) as gen_tok:
self.assertFalse(xsrfutil.validate_token(key, token, user_id,
current_time=curr_time,
action_id=action_id))
gen_tok.assert_called_once_with(key, user_id, action_id=action_id,
when=token_time)
示例4: test_token_differs_from_generated_but_same_length
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_token_differs_from_generated_but_same_length(self):
token_time = 123456789
# Make sure it isn't too old.
curr_time = token_time + xsrfutil.DEFAULT_TIMEOUT_SECS - 1
key = object()
user_id = object()
action_id = object()
token = base64.b64encode(_helpers._to_bytes(str(token_time)))
# It is encoded as b'MTIzNDU2Nzg5', which has length 12.
generated_token = b'M' * 12
# Make sure the token length comparison will succeed, but the token
# comparison will fail.
self.assertEqual(len(token), len(generated_token))
self.assertNotEqual(token, generated_token)
with mock.patch('oauth2client.contrib.xsrfutil.generate_token',
return_value=generated_token) as gen_tok:
self.assertFalse(xsrfutil.validate_token(key, token, user_id,
current_time=curr_time,
action_id=action_id))
gen_tok.assert_called_once_with(key, user_id, action_id=action_id,
when=token_time)
示例5: test_success
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_success(self):
token_time = 123456789
# Make sure it isn't too old.
curr_time = token_time + xsrfutil.DEFAULT_TIMEOUT_SECS - 1
key = object()
user_id = object()
action_id = object()
token = base64.b64encode(_helpers._to_bytes(str(token_time)))
with mock.patch('oauth2client.contrib.xsrfutil.generate_token',
return_value=token) as gen_tok:
self.assertTrue(xsrfutil.validate_token(key, token, user_id,
current_time=curr_time,
action_id=action_id))
gen_tok.assert_called_once_with(key, user_id, action_id=action_id,
when=token_time)
示例6: auth_return
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def auth_return(request):
if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']),
request.user.username):
return HttpResponseBadRequest()
credential = FLOW.step2_exchange(request.GET)
http = httplib2.Http()
http = credential.authorize(http)
resp, data = http.request("https://beam.pro/api/v1/users/current")
data = json.loads(data)
print data
channelId = None
if 'channel' in data:
channelId = data['channel']['id']
name = data['channel'].get("name") or "(unnamed)"
internal_label = "%s-%s" % (channelId, name)
ac = BeamAppCreds(user=request.user, label=internal_label)
ac.save()
storage = Storage(BeamCredentialsModel, 'id', ac, 'credential')
storage.put(credential)
pu = BeamUpdate(credentials=ac, user=request.user, type="beam")
pu.save()
return HttpResponseRedirect("/beam/")
示例7: auth_return
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def auth_return(request):
if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']),
request.user.username):
return HttpResponseBadRequest()
credential = FLOW.step2_exchange(request.GET)
http = httplib2.Http()
http = credential.authorize(http)
resp, data = http.request("https://api.patreon.com/oauth2/api/current_user")
data = json.loads(data)
name = data['data']['attributes'].get("full_name") or "(unnamed)"
internal_label = "%s-%s" % (request.user.id, name)
ac = PatreonAppCreds(user=request.user, label=internal_label)
ac.save()
storage = Storage(PatreonCredentialsModel, 'id', ac, 'credential')
storage.put(credential)
pu = PatreonUpdate(credentials=ac, user=request.user, type="patreon")
pu.save()
return HttpResponseRedirect("/patreon/")
示例8: auth_return
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def auth_return(request):
if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']),
request.user.username):
return HttpResponseBadRequest()
credential = FLOW.step2_exchange(request.GET)
credential = TwitchCredentials.from_json(credential.to_json())
http = httplib2.Http()
http = credential.authorize(http)
resp, data = http.request("https://api.twitch.tv/kraken/user")
data = json.loads(data)
print data
ac = TwitchAppCreds(user=request.user, label=data['name'])
ac.save()
return HttpResponseRedirect("/accounts/")
return render(request, "twitchaccount/label.html", data)
示例9: test_bad_positional
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_bad_positional(self):
# Need 3 positional arguments.
with self.assertRaises(TypeError):
xsrfutil.validate_token(None, None)
# At most 3 positional arguments.
with self.assertRaises(TypeError):
xsrfutil.validate_token(None, None, None, None)
示例10: test_no_token
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_no_token(self):
key = token = user_id = None
self.assertFalse(xsrfutil.validate_token(key, token, user_id))
示例11: test_token_not_valid_base64
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_token_not_valid_base64(self):
key = user_id = None
token = b'a' # Bad padding
self.assertFalse(xsrfutil.validate_token(key, token, user_id))
示例12: test_token_non_integer
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_token_non_integer(self):
key = user_id = None
token = base64.b64encode(b'abc' + xsrfutil.DELIMITER + b'xyz')
self.assertFalse(xsrfutil.validate_token(key, token, user_id))
示例13: test_token_too_old_implicit_current_time
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def test_token_too_old_implicit_current_time(self):
token_time = 123456789
curr_time = token_time + xsrfutil.DEFAULT_TIMEOUT_SECS + 1
key = user_id = None
token = base64.b64encode(_helpers._to_bytes(str(token_time)))
with mock.patch('oauth2client.contrib.xsrfutil.time') as time:
time.time = mock.Mock(name='time', return_value=curr_time)
self.assertFalse(xsrfutil.validate_token(key, token, user_id))
time.time.assert_called_once_with()
示例14: auth_return
# 需要导入模块: from oauth2client.contrib import xsrfutil [as 别名]
# 或者: from oauth2client.contrib.xsrfutil import validate_token [as 别名]
def auth_return(request):
bits = request.GET['state'].split("|")
state_token = bits[0]
redir = ""
if len(bits) > 1:
redir = bits[1]
if not xsrfutil.validate_token(settings.SECRET_KEY, str(state_token),
request.user.username):
return HttpResponseBadRequest()
data = {'state': request.GET['state'], 'code': request.GET['code'], 'redir': redir}
return render(request, "googaccount/label.html", data)