本文整理汇总了Python中social_auth.utils.backend_setting函数的典型用法代码示例。如果您正苦于以下问题:Python backend_setting函数的具体用法?Python backend_setting怎么用?Python backend_setting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了backend_setting函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: complete_process
def complete_process(request, backend, *args, **kwargs):
"""Authentication complete process"""
# pop redirect value before the session is trashed on login()
redirect_value = request.session.get(REDIRECT_FIELD_NAME, '')
user = auth_complete(request, backend, *args, **kwargs)
if isinstance(user, HttpResponse):
return user
if not user and request.user.is_authenticated():
return HttpResponseRedirect(redirect_value)
if user:
if getattr(user, 'is_active', True):
# catch is_new flag before login() might reset the instance
is_new = getattr(user, 'is_new', False)
login(request, user)
# user.social_user is the used UserSocialAuth instance defined
# in authenticate process
social_user = user.social_user
if redirect_value:
request.session[REDIRECT_FIELD_NAME] = redirect_value or \
DEFAULT_REDIRECT
if setting('SOCIAL_AUTH_SESSION_EXPIRATION', True):
# Set session expiration date if present and not disabled by
# setting. Use last social-auth instance for current provider,
# users can associate several accounts with a same provider.
if social_user.expiration_delta():
try:
request.session.set_expiry(social_user.expiration_delta())
except OverflowError:
# Handle django time zone overflow, set default expiry.
request.session.set_expiry(None)
# store last login backend name in session
key = setting('SOCIAL_AUTH_LAST_LOGIN',
'social_auth_last_login_backend')
request.session[key] = social_user.provider
# Remove possible redirect URL from session, if this is a new
# account, send him to the new-users-page if defined.
new_user_redirect = backend_setting(backend,
'SOCIAL_AUTH_NEW_USER_REDIRECT_URL')
if new_user_redirect and is_new:
url = new_user_redirect
else:
url = redirect_value or \
backend_setting(backend,
'SOCIAL_AUTH_LOGIN_REDIRECT_URL') or \
DEFAULT_REDIRECT
else:
url = backend_setting(backend, 'SOCIAL_AUTH_INACTIVE_USER_URL',
LOGIN_ERROR_URL)
else:
msg = setting('LOGIN_ERROR_MESSAGE', None)
if msg:
messages.error(request, msg)
url = backend_setting(backend, 'LOGIN_ERROR_URL', LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:dongshilong,项目名称:Book-Sharing-Portal,代码行数:60,代码来源:views.py
示例2: response
def response(self):
if not hasattr(self, '_response'):
access_token = None
expires = None
if 'code' in self.data:
state = self.validate_state()
url = ACCESS_TOKEN + urlencode({
'client_id': backend_setting(self, self.SETTINGS_KEY_NAME),
'redirect_uri': self.get_redirect_uri(state),
'client_secret': backend_setting(self,
self.SETTINGS_SECRET_NAME),
'code': self.data['code']
})
try:
self._response = cgi.parse_qs(dsa_urlopen(url).read())
except HTTPError:
raise AuthFailed(self, 'There was an error authenticating '
'the app')
if 'signed_request' in self.data:
self._response = load_signed_request(self.data.get('signed_request'),
backend_setting(
self,
self.SETTINGS_SECRET_NAME))
return self._response
开发者ID:JordanReiter,项目名称:django-social-auth,代码行数:26,代码来源:facebook.py
示例3: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError('Incorrect authentication ' + \
'service')
RAISE_EXCEPTIONS = backend_setting(backend, 'SOCIAL_AUTH_RAISE_EXCEPTIONS', setting('DEBUG'))
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
if RAISE_EXCEPTIONS:
raise
log('error', unicode(e), exc_info=True, extra={
'request': request
})
mod, func_name = PROCESS_EXCEPTIONS.rsplit('.', 1)
try:
process = getattr(import_module(mod), func_name,
lambda *args: None)
except ImportError:
pass
else:
process(request, backend, e)
url = backend_setting(backend, 'SOCIAL_AUTH_BACKEND_ERROR_URL',
LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:1st,项目名称:django-social-auth,代码行数:33,代码来源:decorators.py
示例4: auth_complete
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
access_token = None
expires = None
if 'code' in self.data:
state = self.validate_state()
url = ACCESS_TOKEN + urlencode({
'client_id': backend_setting(self, self.SETTINGS_KEY_NAME),
'redirect_uri': self.get_redirect_uri(state),
'client_secret': backend_setting(
self,
self.SETTINGS_SECRET_NAME
),
'code': self.data['code']
})
try:
payload = dsa_urlopen(url)
except HTTPError:
raise AuthFailed(self, 'There was an error authenticating '
'the app')
response = payload.read()
#parsed_response = cgi.parse_qs(response)
parsed_response = json.loads(response)
# print('***********************************************')
# print(url)
# print(response)
# print(parsed_response)
# print(parsed_response['access_token'])
# print(parsed_response['expires_in'])
# print('***********************************************')
access_token = parsed_response['access_token']
if 'expires' in parsed_response:
expires = parsed_response['expires']
if 'signed_request' in self.data:
response = load_signed_request(
self.data.get('signed_request'),
backend_setting(self, self.SETTINGS_SECRET_NAME)
)
if response is not None:
access_token = response.get('access_token') or\
response.get('oauth_token') or\
self.data.get('access_token')
if 'expires' in response:
expires = response['expires']
if access_token:
return self.do_auth(access_token, expires=expires, *args, **kwargs)
else:
if self.data.get('error') == 'access_denied':
raise AuthCanceled(self)
else:
raise AuthException(self)
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:60,代码来源:facebook.py
示例5: associate_complete
def associate_complete(request, backend, *args, **kwargs):
"""Authentication complete process"""
# pop redirect value before the session is trashed on login()
redirect_value = request.session.get(REDIRECT_FIELD_NAME, '')
user = auth_complete(request, backend, request.user, *args, **kwargs)
backend_name = backend.AUTH_BACKEND.name
messages.add_message(
request, messages.SUCCESS,
'You have linked your account with {}.'.format(
settings.AUTH_PROVIDER_LABELS.get(backend_name, backend_name),
)
)
if not user:
url = backend_setting(backend, 'LOGIN_ERROR_URL', LOGIN_ERROR_URL)
elif isinstance(user, HttpResponse):
return user
else:
url = (
redirect_value or
backend_setting(backend, 'SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL') or
DEFAULT_REDIRECT
)
return HttpResponseRedirect(url)
开发者ID:ifduyue,项目名称:sentry,代码行数:26,代码来源:views.py
示例6: auth_complete
def auth_complete(self, request, user, *args, **kwargs):
form = OdnoklassnikiIframeForm(auth=self, data=request.GET)
if not form.is_valid():
raise AuthFailed('Cannot authorize: malformed parameters')
else:
response = form.get_response()
extra_user_data = backend_setting(self, 'ODNOKLASSNIKI_APP_EXTRA_USER_DATA_LIST', ())
base_fields = ('uid', 'first_name', 'last_name', 'name')
fields = base_fields + extra_user_data
data = {
'method': 'users.getInfo',
'uids': '{0}'.format(response['logged_user_id']),
'fields': ','.join(fields),
}
client_key, client_secret, public_key = self.get_settings()
details = odnoklassniki_api(data, response['api_server'], public_key, client_secret, 'iframe_nosession')
if len(details) == 1 and 'uid' in details[0]:
details = details[0]
auth_data_fields = backend_setting(self, 'ODNOKLASSNIKI_APP_EXTRA_AUTH_DATA_LIST',
('api_server', 'apiconnection', 'session_key', 'session_secret_key', 'authorized'))
for field in auth_data_fields:
details[field] = response[field]
details['extra_data_list'] = fields + auth_data_fields
kwargs.update({
'auth': self,
'response': details,
self.AUTH_BACKEND.name: True
})
else:
raise AuthFailed('Cannot get user details: API error')
return authenticate(*args, **kwargs)
开发者ID:1st,项目名称:django-social-auth,代码行数:32,代码来源:odnoklassniki.py
示例7: complete_process
def complete_process(request, backend, *args, **kwargs):
"""Authentication complete process"""
# pop redirect value before the session is trashed on login()
redirect_value = request.session.get(REDIRECT_FIELD_NAME, "")
user = auth_complete(request, backend, *args, **kwargs)
inv_code = request.session.get("code", "")
inv_type = request.session.get("inv_type", "")
if isinstance(user, HttpResponse):
return user
if not user and request.user.is_authenticated():
return HttpResponseRedirect(redirect_value)
if user:
if getattr(user, "is_active", True):
login(request, user)
request.session["code"] = inv_code
request.session["inv_type"] = inv_type
from invite_friends.helpers import accept_invite
accept_invite(request, user)
# user.social_user is the used UserSocialAuth instance defined
# in authenticate process
social_user = user.social_user
if setting("SOCIAL_AUTH_SESSION_EXPIRATION", True):
# Set session expiration date if present and not disabled by
# setting. Use last social-auth instance for current provider,
# users can associate several accounts with a same provider.
if social_user.expiration_delta():
request.session.set_expiry(social_user.expiration_delta())
# store last login backend name in session
key = setting("SOCIAL_AUTH_LAST_LOGIN", "social_auth_last_login_backend")
request.session[key] = social_user.provider
# Remove possible redirect URL from session, if this is a new
# account, send him to the new-users-page if defined.
new_user_redirect = backend_setting(backend, "SOCIAL_AUTH_NEW_USER_REDIRECT_URL")
if new_user_redirect and getattr(user, "is_new", False):
url = new_user_redirect
else:
url = redirect_value or backend_setting(backend, "SOCIAL_AUTH_LOGIN_REDIRECT_URL") or DEFAULT_REDIRECT
else:
url = backend_setting(backend, "SOCIAL_AUTH_INACTIVE_USER_URL", LOGIN_ERROR_URL)
else:
msg = setting("LOGIN_ERROR_MESSAGE", None)
if msg:
messages.error(request, msg)
url = backend_setting(backend, "LOGIN_ERROR_URL", LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:festlv,项目名称:django-social-auth,代码行数:52,代码来源:views.py
示例8: associate_complete
def associate_complete(request, backend, *args, **kwargs):
"""Authentication complete process"""
# pop redirect value before the session is trashed on login()
redirect_value = request.session.get(REDIRECT_FIELD_NAME, "")
user = auth_complete(request, backend, request.user, *args, **kwargs)
if not user:
url = backend_setting(backend, "LOGIN_ERROR_URL", LOGIN_ERROR_URL)
elif isinstance(user, HttpResponse):
return user
else:
url = backend_setting(backend, "SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL") or redirect_value or DEFAULT_REDIRECT
return HttpResponseRedirect(url)
开发者ID:arnaudbreton,项目名称:django-social-auth,代码行数:13,代码来源:views.py
示例9: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError('Incorrect authentication ' + \
'service')
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
if RAISE_EXCEPTIONS:
raise
backend_name = backend.AUTH_BACKEND.name
log('error', unicode(e), exc_info=True,
extra=dict(request=request))
if 'django.contrib.messages' in setting('INSTALLED_APPS'):
from django.contrib.messages.api import error
error(request, unicode(e), extra_tags=backend_name)
else:
log('warn', 'Messages framework not in place, some '+
'errors have not been shown to the user.')
url = backend_setting(backend, 'SOCIAL_AUTH_BACKEND_ERROR_URL',
LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:laprice,项目名称:django-social-auth,代码行数:31,代码来源:views.py
示例10: get_redirect_uri
def get_redirect_uri(self, request, exception):
if self.backend is not None:
return (
backend_setting(self.backend, 'SOCIAL_AUTH_BACKEND_ERROR_URL')
or settings.LOGIN_ERROR_URL
)
return settings.LOGIN_ERROR_URL
开发者ID:duanshuaimin,项目名称:sentry,代码行数:7,代码来源:middleware.py
示例11: user_data
def user_data(self, access_token, *args, **kwargs):
"""
Grab user profile information from facebook.
returns: dict or None
"""
data = None
params = backend_setting(self, self.EXTRA_PARAMS_VAR_NAME, {})
params['access_token'] = access_token
url = FACEBOOK_ME + urlencode(params)
try:
response = dsa_urlopen(url)
data = json.load(response)
except ValueError:
extra = {'access_token': sanitize_log_data(access_token)}
log('error', 'Could not load user data from Facebook.',
exc_info=True, extra=extra)
except HTTPError:
extra = {'access_token': sanitize_log_data(access_token)}
log('error', 'Error validating access token.',
exc_info=True, extra=extra)
raise AuthTokenError(self)
else:
log('debug', 'Found user data for token %s',
sanitize_log_data(access_token), extra={'data': data})
return data
开发者ID:serkanozer,项目名称:django-social-auth,代码行数:28,代码来源:facebook.py
示例12: auth_complete
def auth_complete(self, *args, **kwargs):
if not self.application_auth():
return HttpResponse(self.auth_html())
access_token = None
expires = None
if 'signed_request' in self.data:
response = load_signed_request(
self.data.get('signed_request'),
backend_setting(self, self.SETTINGS_SECRET_NAME)
)
if response is not None:
access_token = response.get('access_token') or\
response.get('oauth_token') or\
self.data.get('access_token')
if 'expires' in response:
expires = response['expires']
if access_token:
return self.do_auth(access_token, expires=expires, *args, **kwargs)
else:
if self.data.get('error') == 'access_denied':
raise AuthCanceled(self)
else:
raise AuthException(self)
开发者ID:mea36,项目名称:django-social-auth,代码行数:28,代码来源:facebook.py
示例13: auth_html
def auth_html(self):
app_id = backend_setting(self, self.SETTINGS_KEY_NAME)
ctx = {
"FACEBOOK_APP_ID": app_id,
"FACEBOOK_EXTENDED_PERMISSIONS": ",".join(backend_setting(self, self.SCOPE_VAR_NAME)),
"FACEBOOK_COMPLETE_URI": self.redirect_uri,
"FACEBOOK_APP_NAMESPACE": APP_NAMESPACE or app_id,
}
try:
fb_template = loader.get_template(LOCAL_HTML)
except TemplateDoesNotExist:
fb_template = loader.get_template_from_string(REDIRECT_HTML)
context = RequestContext(self.request, ctx)
return fb_template.render(context)
开发者ID:yuanxu,项目名称:django-social-auth,代码行数:16,代码来源:facebook.py
示例14: application_auth
def application_auth(self):
required_params = ("user_id", "oauth_token")
data = load_signed_request(self.data.get("signed_request"), backend_setting(self, self.SETTINGS_SECRET_NAME))
for param in required_params:
if not param in data:
return False
return True
开发者ID:yuanxu,项目名称:django-social-auth,代码行数:7,代码来源:facebook.py
示例15: auth_complete
def auth_complete(self, *args, **kwargs):
if not self.application_auth() and "error" not in self.data:
return HttpResponse(self.auth_html())
access_token = None
expires = None
if "signed_request" in self.data:
response = load_signed_request(
self.data.get("signed_request"), backend_setting(self, self.SETTINGS_SECRET_NAME)
)
if response is not None:
access_token = (
response.get("access_token") or response.get("oauth_token") or self.data.get("access_token")
)
if "expires" in response:
expires = response["expires"]
if access_token:
return self.do_auth(access_token, expires=expires, *args, **kwargs)
else:
if self.data.get("error") == "access_denied":
raise AuthCanceled(self)
else:
raise AuthException(self)
开发者ID:yuanxu,项目名称:django-social-auth,代码行数:27,代码来源:facebook.py
示例16: complete
def complete(request, backend, *args, **kwargs):
"""Authentication complete process"""
# pop redirect value before the session is trashed on login()
redirect_value = request.session.get(REDIRECT_FIELD_NAME, "")
backend_name = backend.AUTH_BACKEND.name
try:
user = auth_complete(request, backend, request.user, *args, **kwargs)
except AuthException as exc:
messages.add_message(request, messages.ERROR, six.text_type(exc))
user = None
else:
messages.add_message(
request,
messages.SUCCESS,
"You have linked your account with {}.".format(
settings.AUTH_PROVIDER_LABELS.get(backend_name, backend_name)
),
)
if not user:
url = redirect_value or ASSOCIATE_ERROR_URL or DEFAULT_REDIRECT
elif isinstance(user, HttpResponse):
return user
else:
url = redirect_value or backend_setting(backend, "SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL") or DEFAULT_REDIRECT
return HttpResponseRedirect(url)
开发者ID:alexm92,项目名称:sentry,代码行数:28,代码来源:views.py
示例17: wrapper
def wrapper(request, backend, *args, **kwargs):
if redirect_name:
redirect = reverse(redirect_name, args=(backend,))
else:
redirect = request.path
backend = get_backend(backend, request, redirect)
if not backend:
return HttpResponseServerError(
"Incorrect authentication " + "service or service API settings not available!"
)
try:
return func(request, backend, *args, **kwargs)
except Exception, e: # some error ocurred
if RAISE_EXCEPTIONS:
raise
backend_name = backend.AUTH_BACKEND.name
log("error", unicode(e), exc_info=True, extra=dict(request=request))
if "django.contrib.messages" in setting("INSTALLED_APPS"):
from django.contrib.messages.api import error
error(request, unicode(e), extra_tags=backend_name)
else:
log("warn", "Messages framework not in place, some " + "errors have not been shown to the user.")
url = backend_setting(backend, "SOCIAL_AUTH_BACKEND_ERROR_URL", LOGIN_ERROR_URL)
return HttpResponseRedirect(url)
开发者ID:festlv,项目名称:django-social-auth,代码行数:30,代码来源:views.py
示例18: user_data
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
data = None
params = backend_setting(self, self.EXTRA_PARAMS_VAR_NAME, {})
params['access_token'] = access_token
url = FACEBOOK_ME + urlencode(params)
try:
response = requests.get(url)
if response.status_code == 200:
data = simplejson.loads(response.text)
else:
raise AuthTokenError()
except ValueError:
extra = {'access_token': sanitize_log_data(access_token)}
log('error', 'Could not load user data from Facebook.',
exc_info=True, extra=extra)
except requests.RequestException:
extra = {'access_token': sanitize_log_data(access_token)}
log('error', 'Error validating access token.',
exc_info=True, extra=extra)
raise AuthTokenError(self)
else:
log('debug', 'Found user data for token %s',
sanitize_log_data(access_token), extra={'data': data})
return data
开发者ID:talos,项目名称:django-social-auth-norel,代码行数:26,代码来源:facebook.py
示例19: disconnect
def disconnect(request, backend, association_id=None):
"""Disconnects given backend from current logged in user."""
backend.disconnect(request.user, association_id)
url = request.REQUEST.get(REDIRECT_FIELD_NAME, '') or \
backend_setting(backend, 'SOCIAL_AUTH_DISCONNECT_REDIRECT_URL') or \
DEFAULT_REDIRECT
return HttpResponseRedirect(url)
开发者ID:SeyZ,项目名称:django-social-auth,代码行数:7,代码来源:views.py
示例20: get_auth_sig
def get_auth_sig(self):
secret_key = backend_setting(self.auth, 'ODNOKLASSNIKI_APP_SECRET')
hash_source = '{0:d}{1:s}{2:s}'.format(
self.cleaned_data['logged_user_id'],
self.cleaned_data['session_key'],
secret_key
)
return md5(hash_source).hexdigest()
开发者ID:jefftriplett,项目名称:django-social-auth,代码行数:8,代码来源:odnoklassniki.py
注:本文中的social_auth.utils.backend_setting函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论