本文整理汇总了Python中social.utils.parse_qs函数的典型用法代码示例。如果您正苦于以下问题:Python parse_qs函数的具体用法?Python parse_qs怎么用?Python parse_qs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_qs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_login
def do_login(self, after_complete_checks=True, user_data_body=None,
expected_username=None):
self.strategy.set_settings({
'SOCIAL_AUTH_GITHUB_KEY': 'a-key',
'SOCIAL_AUTH_GITHUB_SECRET': 'a-secret-key',
'SOCIAL_AUTH_LOGIN_REDIRECT_URL': self.login_redirect_url,
'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': (
'social.backends.github.GithubOAuth2',
)
})
start_url = do_auth(self.strategy).url
target_url = self.strategy.build_absolute_uri(
'/complete/github/?code=foobar'
)
start_query = parse_qs(urlparse(start_url).query)
location_url = target_url + ('?' in target_url and '&' or '?') + \
'state=' + start_query['state']
location_query = parse_qs(urlparse(location_url).query)
HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
location=location_url)
HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
body='foobar')
response = requests.get(start_url)
expect(response.url).to.equal(location_url)
expect(response.text).to.equal('foobar')
HTTPretty.register_uri(HTTPretty.GET,
uri=self.backend.ACCESS_TOKEN_URL,
status=200,
body=self.access_token_body or '',
content_type='text/json')
if self.user_data_url:
user_data_body = user_data_body or self.user_data_body or ''
HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
body=user_data_body,
content_type='text/json')
self.strategy.set_request_data(location_query)
class Request(object):session = {}
self.strategy.request = Request()
def _login_lambda(strategy, user, social_user):
strategy.request = Request()
return strategy.session_set('username', user.username)
redirect = do_complete(
self.strategy,
user=self.user,
login=_login_lambda
)
if after_complete_checks:
expect(self.strategy.session_get('username')).to.equal(
expected_username or self.expected_username
)
expect(redirect.url).to.equal(self.login_redirect_url)
return redirect
示例2: auth_by_token
def auth_by_token(request, backend):
key, secret = request.backend.get_key_and_secret()
response = requests.get(request.backend.ACCESS_TOKEN_URL, params={
'client_id': key,
'redirect_uri': request.data.get('redirect_uri'),
'client_secret': secret,
'code': request.data.get('code')
})
try:
response = response.json()
except ValueError:
response = parse_qs(response.text)
try:
access_token = response['access_token']
# check if user has signed up
email = request.backend.user_data(access_token).get('email')
try:
User.objects.get(email=email)
new_user = False
except User.DoesNotExist:
new_user = True
return new_user, request.backend.do_auth(access_token)
except KeyError:
raise APIException(response['error']['message'])
示例3: run_oauth
def run_oauth(self, m, user=None):
strategy = DjangoStrategy(DjangoStorage)
backend = self.Backend_Class(strategy, redirect_uri=self.client_complete_url)
start_url = do_auth(backend).url
start_query = parse_qs(urlparse(start_url).query)
# set 'state' in client
backend.data.update({'state': start_query['state']})
m.get(backend.USER_DATA_URL,
json={"username": self.social_username,
"email": self.social_email},
status_code=200)
m.post(backend.ACCESS_TOKEN_URL,
json={'access_token': self.access_token,
'token_type': self.token_type,
'expires_in': self.expires_in,
'scope': self.scope,
'refresh_token': self.refresh_token},
status_code=200)
def _login(backend, user, social_user):
backend.strategy.session_set('username', user.username)
do_complete(backend, user=user, login=_login)
social = backend.strategy.storage.user.get_social_auth(backend.name, self.social_username)
return strategy.session_get('username'), social, backend
示例4: test_disconnect_with_partial_pipeline
def test_disconnect_with_partial_pipeline(self):
self.strategy.set_settings({
'SOCIAL_AUTH_DISCONNECT_PIPELINE': (
'social.pipeline.partial.save_status_to_session',
'social.tests.pipeline.ask_for_password',
'social.tests.pipeline.set_password',
'social.pipeline.disconnect.allowed_to_disconnect',
'social.pipeline.disconnect.get_entries',
'social.pipeline.disconnect.revoke_tokens',
'social.pipeline.disconnect.disconnect'
)
})
self.do_login()
user = User.get(self.expected_username)
redirect = do_disconnect(self.backend, user)
url = self.strategy.build_absolute_uri('/password')
expect(redirect.url).to.equal(url)
HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
body='foobar')
HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)
password = 'foobar'
requests.get(url)
requests.post(url, data={'password': password})
data = parse_qs(HTTPretty.last_request.body)
expect(data['password']).to.equal(password)
self.strategy.session_set('password', data['password'])
redirect = do_disconnect(self.backend, user)
expect(len(user.social)).to.equal(0)
示例5: auth_complete
def auth_complete(self, *args, **kwargs):
"""Return user, might be logged in"""
# Multiple unauthorized tokens are supported (see #521)
self.process_error(self.data)
name = self.name + 'unauthorized_token_name'
token = None
unauthed_tokens = self.strategy.session_get(name, [])
if not unauthed_tokens:
raise AuthTokenError(self, 'Missing unauthorized token')
token_param_name = self.OAUTH_TOKEN_PARAMETER_NAME
data_token = self.data.get(token_param_name, 'no-token')
for unauthed_token in unauthed_tokens:
orig_unauthed_token = unauthed_token
if not isinstance(unauthed_token, dict):
unauthed_token = parse_qs(unauthed_token)
if unauthed_token.get(token_param_name) == data_token:
self.strategy.session_set(name, list(
set(unauthed_tokens) -
set([orig_unauthed_token]))
)
token = unauthed_token
break
else:
raise AuthTokenError(self, 'Incorrect tokens')
try:
access_token = self.access_token(token)
except HTTPError as err:
if err.response.status_code == 400:
raise AuthCanceled(self)
else:
raise
return self.do_auth(access_token, *args, **kwargs)
示例6: parse_nonce_and_return_access_token_body
def parse_nonce_and_return_access_token_body(self, request, _url, headers):
"""
Get the nonce from the request parameters, add it to the id_token, and
return the complete response.
"""
nonce = parse_qs(request.body).get('nonce')
body = self.prepare_access_token_body(nonce=nonce)
return 200, headers, body
示例7: do_start
def do_start(self):
start_url = self.strategy.start().url
target_url = self.auth_handlers(start_url)
response = requests.get(start_url)
expect(response.url).to.equal(target_url)
expect(response.text).to.equal('foobar')
self.strategy.set_request_data(parse_qs(urlparse(target_url).query))
return self.strategy.complete()
示例8: handle_state
def handle_state(self, start_url, target_url):
start_query = parse_qs(urlparse(start_url).query)
redirect_uri = start_query.get('redirect_uri')
if getattr(self.backend, 'STATE_PARAMETER', False):
if start_query.get('state'):
target_url = url_add_parameters(target_url, {
'state': start_query['state']
})
if redirect_uri and getattr(self.backend, 'REDIRECT_STATE', False):
redirect_query = parse_qs(urlparse(redirect_uri).query)
if redirect_query.get('redirect_state'):
target_url = url_add_parameters(target_url, {
'redirect_state': redirect_query['redirect_state']
})
return target_url
示例9: do_login
def do_login(self, after_complete_checks=True, user_data_body=None, expected_username=None):
self.strategy.set_settings(
{
"SOCIAL_AUTH_GITHUB_KEY": "a-key",
"SOCIAL_AUTH_GITHUB_SECRET": "a-secret-key",
"SOCIAL_AUTH_LOGIN_REDIRECT_URL": self.login_redirect_url,
"SOCIAL_AUTH_AUTHENTICATION_BACKENDS": ("social.backends.github.GithubOAuth2",),
}
)
start_url = do_auth(self.backend).url
target_url = self.strategy.build_absolute_uri("/complete/github/?code=foobar")
start_query = parse_qs(urlparse(start_url).query)
location_url = target_url + ("?" in target_url and "&" or "?") + "state=" + start_query["state"]
location_query = parse_qs(urlparse(location_url).query)
HTTPretty.register_uri(HTTPretty.GET, start_url, status=301, location=location_url)
HTTPretty.register_uri(HTTPretty.GET, location_url, status=200, body="foobar")
response = requests.get(start_url)
expect(response.url).to.equal(location_url)
expect(response.text).to.equal("foobar")
HTTPretty.register_uri(
HTTPretty.POST,
uri=self.backend.ACCESS_TOKEN_URL,
status=200,
body=self.access_token_body or "",
content_type="text/json",
)
if self.user_data_url:
user_data_body = user_data_body or self.user_data_body or ""
HTTPretty.register_uri(HTTPretty.GET, self.user_data_url, body=user_data_body, content_type="text/json")
self.strategy.set_request_data(location_query, self.backend)
def _login(backend, user, social_user):
backend.strategy.session_set("username", user.username)
redirect = do_complete(self.backend, user=self.user, login=_login)
if after_complete_checks:
expect(self.strategy.session_get("username")).to.equal(expected_username or self.expected_username)
expect(redirect.url).to.equal(self.login_redirect_url)
return redirect
示例10: do_auth
def do_auth(self, access_token, *args, **kwargs):
"""Finish the auth process once the access_token was retrieved"""
if not isinstance(access_token, dict):
access_token = parse_qs(access_token)
data = self.user_data(access_token)
if data is not None and 'access_token' not in data:
data['access_token'] = access_token
kwargs.update({'response': data, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
示例11: do_start
def do_start(self):
start_url = self.backend.start().url
target_url = self.auth_handlers(start_url)
response = requests.get(start_url)
self.assertEqual(response.url, target_url)
self.assertEqual(response.text, 'foobar')
self.strategy.set_request_data(parse_qs(urlparse(target_url).query),
self.backend)
return self.backend.complete()
示例12: pipeline_slug_handling
def pipeline_slug_handling(self, url):
slug = 'foo-bar'
requests.get(url)
requests.post(url, data={'slug': slug})
data = parse_qs(HTTPretty.last_request.body)
expect(data['slug']).to.equal(slug)
self.strategy.session_set('slug', data['slug'])
return slug
示例13: pipeline_password_handling
def pipeline_password_handling(self, url):
password = 'foobar'
requests.get(url)
requests.post(url, data={'password': password})
data = parse_qs(HTTPretty.last_request.body)
expect(data['password']).to.equal(password)
self.strategy.session_set('password', data['password'])
return password
示例14: oauth_authorization_request
def oauth_authorization_request(self, token):
"""Generate OAuth request to authorize token."""
if not isinstance(token, dict):
token = parse_qs(token)
params = self.auth_extra_arguments() or {}
params.update(self.get_scope_argument())
params['oauth_token'] = token.get('oauth_token')
params['redirect_uri'] = self.redirect_uri
return self.AUTHORIZATION_URL + '?' + urlencode(params)
示例15: oauth_authorization_request
def oauth_authorization_request(self, token):
"""Generate OAuth request to authorize token."""
if not isinstance(token, dict):
token = parse_qs(token)
params = self.auth_extra_arguments() or {}
params.update(self.get_scope_argument())
params[self.OAUTH_TOKEN_PARAMETER_NAME] = token.get(self.OAUTH_TOKEN_PARAMETER_NAME)
state = self.get_or_create_state()
params[self.REDIRECT_URI_PARAMETER_NAME] = self.get_redirect_uri(state)
return "{0}?{1}".format(self.authorization_url(), urlencode(params))