本文整理汇总了Python中openid.extensions.sreg.SRegRequest方法的典型用法代码示例。如果您正苦于以下问题:Python sreg.SRegRequest方法的具体用法?Python sreg.SRegRequest怎么用?Python sreg.SRegRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openid.extensions.sreg
的用法示例。
在下文中一共展示了sreg.SRegRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach_reg_info
# 需要导入模块: from openid.extensions import sreg [as 别名]
# 或者: from openid.extensions.sreg import SRegRequest [as 别名]
def attach_reg_info(self, auth_request, keys, optional_keys):
"""Attaches sreg and ax requests to the auth request.
:internal:
"""
keys = set(keys or [])
optional_keys = set(optional_keys or [])
sreg_keys = list(SREG_KEYS & keys)
sreg_optional_keys = list(SREG_KEYS & optional_keys)
auth_request.addExtension(SRegRequest(required=sreg_keys,
optional=sreg_optional_keys))
ax_req = ax.FetchRequest()
for key in (keys | optional_keys):
for uri in AX_MAPPING.get(key, ()):
ax_req.add(ax.AttrInfo(uri, required=key in REQUIRED_KEYS))
auth_request.addExtension(ax_req)
示例2: _add_extensions
# 需要导入模块: from openid.extensions import sreg [as 别名]
# 或者: from openid.extensions.sreg import SRegRequest [as 别名]
def _add_extensions(self, oidrequest):
"""Add extensions to the oidrequest"""
sreg_request = sreg.SRegRequest(required=self._REQUIRED_ATTRIBUTES,
optional=self._OPTIONAL_ATTRIBUTES)
oidrequest.addExtension(sreg_request)
ax_request = ax.FetchRequest()
for alias in self._REQUIRED_ATTRIBUTES:
uri = utils.SREG2AX[alias]
ax_request.add(ax.AttrInfo(uri, required=True, alias=alias))
for alias in self._OPTIONAL_ATTRIBUTES:
uri = utils.SREG2AX[alias]
ax_request.add(ax.AttrInfo(uri, required=False, alias=alias))
oidrequest.addExtension(ax_request)
示例3: begin
# 需要导入模块: from openid.extensions import sreg [as 别名]
# 或者: from openid.extensions.sreg import SRegRequest [as 别名]
def begin(self, oid, realm, return_to_url):
"""
Begin the OpenID authentication
"""
w2popenid = self.session.w2popenid
w2popenid.oid = oid
auth_req = self.consumer.begin(oid)
auth_req.addExtension(SRegRequest(required=['email', 'nickname']))
url = auth_req.redirectURL(return_to=return_to_url, realm=realm)
return url
示例4: login
# 需要导入模块: from openid.extensions import sreg [as 别名]
# 或者: from openid.extensions.sreg import SRegRequest [as 别名]
def login(request):
if 'openid' in request.GET or request.method == 'POST':
form = LoginForm(
dict(list(request.GET.items()) + list(request.POST.items()))
)
if form.is_valid():
client = _openid_consumer(request)
try:
auth_request = client.begin(form.cleaned_data['openid'])
if QUERY_EMAIL:
sreg = SRegRequest()
for name in SRegFields:
sreg.requestField(field_name=name,
required=True)
auth_request.addExtension(sreg)
ax = FetchRequest()
for name in AXAttributes:
ax.add(AttrInfo(name,
required=True))
auth_request.addExtension(ax)
callback_url = reverse(callback)
SocialLogin.stash_state(request)
redirect_url = auth_request.redirectURL(
request.build_absolute_uri('/'),
request.build_absolute_uri(callback_url))
return HttpResponseRedirect(redirect_url)
# UnicodeDecodeError:
# see https://github.com/necaris/python3-openid/issues/1
except (UnicodeDecodeError, DiscoveryFailure) as e:
if request.method == 'POST':
form._errors["openid"] = form.error_class([e])
else:
return render_authentication_error(
request,
OpenIDProvider.id,
exception=e)
else:
form = LoginForm(initial={'next': request.GET.get('next'),
'process': request.GET.get('process')})
d = dict(form=form)
return render(request, "openid/login.html", d)
示例5: setup_request
# 需要导入模块: from openid.extensions import sreg [as 别名]
# 或者: from openid.extensions.sreg import SRegRequest [as 别名]
def setup_request(self, params=None):
"""Setup request"""
request = self.openid_request(params)
# Request some user details. Use attribute exchange if provider
# advertises support.
if request.endpoint.supportsType(ax.AXMessage.ns_uri):
fetch_request = ax.FetchRequest()
# Mark all attributes as required, Google ignores optional ones
for attr, alias in self.get_ax_attributes():
fetch_request.add(ax.AttrInfo(attr, alias=alias,
required=True))
else:
fetch_request = sreg.SRegRequest(
optional=list(dict(self.get_sreg_attributes()).keys())
)
request.addExtension(fetch_request)
# Add PAPE Extension for if configured
preferred_policies = self.setting(
'OPENID_PAPE_PREFERRED_AUTH_POLICIES'
)
preferred_level_types = self.setting(
'OPENID_PAPE_PREFERRED_AUTH_LEVEL_TYPES'
)
max_age = self.setting('OPENID_PAPE_MAX_AUTH_AGE')
if max_age is not None:
try:
max_age = int(max_age)
except (ValueError, TypeError):
max_age = None
if max_age is not None or preferred_policies or preferred_level_types:
pape_request = pape.Request(
max_auth_age=max_age,
preferred_auth_policies=preferred_policies,
preferred_auth_level_types=preferred_level_types
)
request.addExtension(pape_request)
return request
示例6: start_openid
# 需要导入模块: from openid.extensions import sreg [as 别名]
# 或者: from openid.extensions.sreg import SRegRequest [as 别名]
def start_openid(session, openid_url, trust_root, return_to):
"""
Start the OpenID authentication process.
* Requests some Simple Registration data using the OpenID
library's Simple Registration machinery
* Generates the appropriate trust root and return URL values for
this application (tweak where appropriate)
* Generates the appropriate redirect based on the OpenID protocol
version.
"""
# Start OpenID authentication.
c = get_consumer(session)
error = None
try:
auth_request = c.begin(openid_url)
except DiscoveryFailure, e:
# Some other protocol-level failure occurred.
error = "OpenID discovery error: %s" % (str(e),)
if error:
raise Exception("error in openid")
# Add Simple Registration request information. Some fields
# are optional, some are required. It's possible that the
# server doesn't support sreg or won't return any of the
# fields.
sreg_request = sreg.SRegRequest(required=['email'],
optional=[])
auth_request.addExtension(sreg_request)
# Add Attribute Exchange request information.
ax_request = ax.FetchRequest()
# XXX - uses myOpenID-compatible schema values, which are
# not those listed at axschema.org.
for k, v in AX_REQUIRED_FIELDS.iteritems():
ax_request.add(ax.AttrInfo(v, required=True))
auth_request.addExtension(ax_request)
# Compute the trust root and return URL values to build the
# redirect information.
# trust_root = util.getViewURL(request, startOpenID)
# return_to = util.getViewURL(request, finishOpenID)
# Send the browser to the server either by sending a redirect
# URL or by generating a POST form.
url = auth_request.redirectURL(trust_root, return_to)
return url