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


Python xsrfutil.validate_token方法代碼示例

本文整理匯總了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 
開發者ID:0x0ece,項目名稱:oscars2016,代碼行數:23,代碼來源:appengine.py

示例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 
開發者ID:taers232c,項目名稱:GAMADV-XTD,代碼行數:20,代碼來源:appengine.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:22,代碼來源:test_xsrfutil.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:25,代碼來源:test_xsrfutil.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:18,代碼來源:test_xsrfutil.py

示例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/") 
開發者ID:google,項目名稱:mirandum,代碼行數:24,代碼來源:views.py

示例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/") 
開發者ID:google,項目名稱:mirandum,代碼行數:20,代碼來源:views.py

示例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) 
開發者ID:google,項目名稱:mirandum,代碼行數:19,代碼來源:views.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:9,代碼來源:test_xsrfutil.py

示例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)) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:5,代碼來源:test_xsrfutil.py

示例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)) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:6,代碼來源:test_xsrfutil.py

示例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)) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:6,代碼來源:test_xsrfutil.py

示例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() 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:12,代碼來源:test_xsrfutil.py

示例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) 
開發者ID:google,項目名稱:mirandum,代碼行數:13,代碼來源:views.py


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