本文整理汇总了Python中openid.consumer.consumer.Consumer.begin方法的典型用法代码示例。如果您正苦于以下问题:Python Consumer.begin方法的具体用法?Python Consumer.begin怎么用?Python Consumer.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openid.consumer.consumer.Consumer
的用法示例。
在下文中一共展示了Consumer.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _1
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def _1(request):
consumer = Consumer(request.session, DjangoOpenIDStore())
realm = "http://" + request.get_host()
redirect_url = "http://" + request.get_host() + reverse('flexible_auth:auth-process', args=[cls.SERVICE_NAME, step+1])
# catch Google Apps domain that is referring, if any
_domain = None
if 'domain' in request.POST:
_domain = request.POST['domain']
elif 'domain' in request.GET:
_domain = request.GET['domain']
try:
# two different endpoints depending on whether the using is using Google Account or Google Apps Account
if _domain:
auth_request = consumer.begin(cls.GOOGLE_APPS_URL % _domain)
else:
auth_request = consumer.begin(cls.GOOGLE_URL)
except DiscoveryFailure as e:
return CustomError(request, "Google Accounts Error", "Google's OpenID endpoint is not available.")
# add requests for additional account information required, in this case: email, first name & last name + oauth token
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'mode', 'fetch_request')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'required', 'email,firstname,lastname')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.email', 'http://schema.openid.net/contact/email')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.firstname', 'http://axschema.org/namePerson/first')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.lastname', 'http://axschema.org/namePerson/last')
return redirect(auth_request.redirectURL(realm, redirect_url))
示例2: login
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def login(self):
consumer = Consumer(session, SOOpenIDStore())
# catch Google Apps domain that is referring, if any
domain = None
if 'domain' in request.POST:
domain = request.POST['domain']
elif 'domain' in request.GET:
domain = request.GET['domain']
try:
# two different endpoints depending on whether the using is using Google Account or Google Apps Account
if domain:
auth_request = consumer.begin('https://www.google.com/accounts/o8/site-xrds?hd=%s' % domain)
else:
auth_request = consumer.begin('https://www.google.com/accounts/o8/id')
except DiscoveryFailure as e:
flash ("Google Accounts Error : Google's OpenID endpoint is not available.")
return redirect("/user/show_login")
# add requests for additional account information required, in my case: email
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'mode', 'fetch_request')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'required', 'email')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.email', 'http://schema.openid.net/contact/email')
return redirect(auth_request.redirectURL(url('/', qualified=True), url(controller='user', action='google_login_response', qualified=True)))
示例3: google_signin
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def google_signin(request):
""" This is the view where the Google account login icon on your site points to, e.g. http://www.yourdomain.com/google-signin """
consumer = Consumer(request.session, DjangoOpenIDStore())
# catch Google Apps domain that is referring, if any
_domain = None
if 'domain' in request.POST:
_domain = request.POST['domain']
elif 'domain' in request.GET:
_domain = request.GET['domain']
try:
# two different endpoints depending on whether the using is using Google Account or Google Apps Account
if _domain:
auth_request = consumer.begin('https://www.google.com/accounts/o8/site-xrds?hd=%s' % _domain)
else:
auth_request = consumer.begin('https://www.google.com/accounts/o8/id')
except DiscoveryFailure as e:
return CustomError(request, "Google Accounts Error", "Google's OpenID endpoint is not available.")
# add requests for additional account information required, in my case: email, first name & last name
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'mode', 'fetch_request')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'required', 'email,firstname,lastname')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.email', 'http://schema.openid.net/contact/email')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.firstname', 'http://axschema.org/namePerson/first')
auth_request.addExtensionArg('http://openid.net/srv/ax/1.0', 'type.lastname', 'http://axschema.org/namePerson/last')
return redirect(auth_request.redirectURL('http://localhost', 'http://localhost/post_login'))
示例4: google_login
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def google_login(self):
openid_session = session.get("openid_session", {})
openid_store = None # stateless
cons = Consumer(openid_session, openid_store)
GOOGLE_OPENID = 'https://www.google.com/accounts/o8/id'
openid = GOOGLE_OPENID
try:
authrequest = cons.begin(openid)
except DiscoveryFailure:
h.flash(_('Authentication failed, please try again.'))
redirect(c.came_from or url(controller='home', action='index'))
ax_req = ax.FetchRequest()
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/first',
alias='firstname', required=True))
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/last',
alias='lastname', required=True))
ax_req.add(ax.AttrInfo('http://schema.openid.net/contact/email',
alias='email', required=True))
authrequest.addExtension(ax_req)
kargs = self._auth_args()
redirecturl = authrequest.redirectURL(
url('frontpage', qualified=True),
return_to=url(controller='federation', action='google_verify',
qualified=True, **kargs))
session['openid_session'] = openid_session
session.save()
redirect(redirecturl)
示例5: _fn
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def _fn(*args, **kwargs):
if not session.get('logged_in', False):
c = Consumer(session, openid_store)
url = c.begin(openid_identity).redirectURL(url_for('index', _external=True), url_for('verify_identity', _external=True))
return redirect(url)
else:
return fn(*args, **kwargs)
示例6: __call__
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def __call__(self):
request = self.request
siteURL = u'%s/'%absoluteURL(getSite(), request)
if not IUnauthenticatedPrincipal.providedBy(request.principal):
request.response.redirect(siteURL)
return u''
if not 'openid_form_submitted' in request:
request.response.redirect(siteURL)
return u''
identifier = request.get('openid_identifier')
if not identifier:
IStatusMessage(request).add(
_(u"Please specify your OpenID identifier."))
request.response.redirect(siteURL)
return u''
authenticator = getUtility(IOpenIdAuthenticator)
session = ISession(request)[SESSION_KEY]
consumer = Consumer(session, authenticator.store)
try:
authRequest = consumer.begin(identifier)
redirectURL = authRequest.redirectURL(
siteURL, getReturnToURL(request))
except Exception, err:
IStatusMessage(request).add(err, 'error')
redirectURL = siteURL
示例7: process_request
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def process_request(self, request):
if request.path_info[0:7] != '/admin/':
return None
if 'openid_username' not in request.session:
request.session['openid_session'] = {}
consumer = Consumer(request.session['openid_session'], None)
# auth request to google has not been made yet
if 'openid.mode' not in request.REQUEST:
ax_request = ax.FetchRequest()
ax_request.add(ax.AttrInfo('http://axschema.org/contact/email', required = True))
auth_request = consumer.begin('https://www.google.com/accounts/o8/id')
auth_request.addExtension(ax_request)
url = auth_request.redirectURL(
request.build_absolute_uri('/'),
return_to=request.build_absolute_uri())
return redirect(url)
# auth request has been made, thus analyse google response
else:
info = consumer.complete(request.REQUEST, request.build_absolute_uri())
if info.status == SUCCESS:
ax_response = ax.FetchResponse.fromSuccessResponse(info)
username = ax_response.get('http://axschema.org/contact/email')[0]
request.session['openid_username'] = username
username = request.session.get('openid_username', None)
if username not in AUTHORIZED_EMAILS:
if username: del request.session['openid_username']
return HttpResponse('403 Forbidden', status=403)
示例8: ask_openid
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def ask_openid(request, openid_url=None, next_url=None, on_failure=None):
""" basic function to ask openid and return response """
on_failure = on_failure or signin_failure
sreg_request = sreg.SRegRequest(optional=["nickname", "email"])
trust_root = getattr(settings, "OPENID_TRUST_ROOT", get_url_host(request) + "/")
if xri.identifierScheme(openid_url) == "XRI" and getattr(settings, "OPENID_DISALLOW_INAMES", False):
msg = _("i-names are not supported")
logging.debug("openid failed because i-names are not supported")
return on_failure(request, msg)
consumer = Consumer(request.session, util.DjangoOpenIDStore())
try:
auth_request = consumer.begin(openid_url)
except DiscoveryFailure:
msg = _(u"OpenID %(openid_url)s is invalid" % {"openid_url": openid_url})
logging.debug(msg)
return on_failure(request, msg)
logging.debug("openid seemed to work")
if sreg_request:
logging.debug("adding sreg_request - wtf it is?")
auth_request.addExtension(sreg_request)
redirect_to = "%s%s?%s" % (
get_url_host(request),
reverse("user_complete_openid_signin"),
urllib.urlencode({"next": next_url}),
)
redirect_url = auth_request.redirectURL(trust_root, redirect_to)
logging.debug("redirecting to %s" % redirect_url)
return HttpResponseRedirect(redirect_url)
示例9: signin
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def signin(request, redirect_to=None):
trust_root = getattr(
settings, 'OPENID_TRUST_ROOT', get_url_host(request) + '/'
)
# foo derbis.
redirect_to = redirect_to or reverse('openid_complete')
# In case they were lazy...
if not redirect_to.startswith('http://') or redirect_to.startswith('https://'):
redirect_to = get_url_host(request) + redirect_to
if request.GET.get('next') and is_valid_next_url(request.GET['next']):
if '?' in redirect_to:
join = '&'
else:
join = '?'
redirect_to += join + urllib.urlencode({
'next': request.GET['next']
})
if xri.identifierScheme(STEAM_PROVIDER_URL) == 'XRI' and getattr(
settings, 'OPENID_DISALLOW_INAMES', False
):
return on_failure(request, 'i-names are not supported')
consumer = Consumer(request.session, DjangoOpenIDStore())
try:
auth_request = consumer.begin(STEAM_PROVIDER_URL)
except DiscoveryFailure:
return on_failure(request, 'The OpenID was invalid')
redirect_url = auth_request.redirectURL(trust_root, redirect_to)
return HttpResponseRedirect(redirect_url)
示例10: __call__
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def __call__(self, *args, **kw):
request = self.request
context = self.context
siteURL = u'%s/'%absoluteURL(context, request)
if not IUnauthenticatedPrincipal.providedBy(request.principal):
self.redirect(siteURL)
return u''
if not 'openid_form_submitted' in request:
self.redirect(siteURL)
return u''
identifier = request.get('openid_identifier')
if not identifier or identifier == 'http://':
IStatusMessage(request).add(
_(u"Please specify your OpenID identifier."))
self.redirect(u'%slogin.html'%siteURL)
return u''
authenticator = getUtility(IUsersPlugin)
session = ISession(request)[SESSION_KEY]
consumer = Consumer(session, authenticator.store)
try:
authRequest = consumer.begin(identifier)
redirectURL = authRequest.redirectURL(
siteURL, getReturnToURL(request))
except Exception, err:
IStatusMessage(request).add(err, 'error')
self.redirect(u'%slogin.html'%siteURL)
return u''
示例11: get_auth_redirect_url
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def get_auth_redirect_url(cls, identifier):
s = FileOpenIDStore(cherrypy.request.app.config['appSettings']['openid.datastore_directory'])
consumer = Consumer(session=cherrypy.session, store=s)
authRequest = consumer.begin(identifier)
return authRequest.redirectURL(
realm=ApplicationPaths.get_site_root(),
return_to=ApplicationPaths.get_handle_openid_auth_response_path())
示例12: libopenid
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def libopenid(request, domain):
if request.user is not None and request.user.is_authenticated():
return redirect(to="http://%s/" % request.get_host())
if domain is 'default':
discovery_url = "https://www.google.com/accounts/o8/id"
else:
discovery_url = "https://www.google.com/accounts/o8/site-xrds?hd=%s" % domain
consumer = Consumer(request.session, FileOpenIDStore('/tmp/gtugdemo'))
auth_request = consumer.begin(discovery_url)
ax_request = ax.FetchRequest()
ax_request.add(ax.AttrInfo('http://axschema.org/namePerson/first',required=True))
ax_request.add(ax.AttrInfo('http://axschema.org/namePerson/last',required=True))
ax_request.add(ax.AttrInfo('http://axschema.org/contact/email',required=True))
auth_request.addExtension(ax_request)
redirect_url = auth_request.redirectURL(realm='http://%s/' % request.get_host(), return_to='http://%s/login/callback' % request.get_host())
oauth_query = {
'openid.ns.oauth': 'http://specs.openid.net/extensions/oauth/1.0',
'openid.oauth.consumer': request.get_host(),
'openid.oauth.scope': ' '.join(OAUTH_SCOPE),
}
redirect_url += "&%s" % urlencode(oauth_query)
print redirect_url
#print str(request.session.keys())
#return render_to_response('login.html', locals(), context_instance=RequestContext(request))
return redirect(to=redirect_url)
示例13: begin
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def begin(request, openid_url):
request.session['request_referer'] = urlparse.urljoin(request.META.get('HTTP_REFERER', ''), '/')
consumer = Consumer(request.session, DjangoOpenIDStore())
try:
auth_request = consumer.begin(openid_url)
except DiscoveryFailure:
return on_failure(request, _('The OpenID was invalid'))
s = SRegRequest()
for sarg in OPENID_SREG:
if sarg.lower().lstrip() == "policy_url":
s.policy_url = OPENID_SREG[sarg]
else:
for v in OPENID_SREG[sarg].split(','):
s.requestField(field_name=v.lower().lstrip(), required=(sarg.lower().lstrip() == "required"))
auth_request.addExtension(s)
axr = AXFetchRequest()
for i in OPENID_AX:
axr.add(AttrInfo(i['type_uri'], i['count'], i['required'], i['alias']))
auth_request.addExtension(axr)
redirect_url = auth_request.redirectURL(get_trusted_root(request),
request.build_absolute_uri(reverse("openid_complete")))
return HttpResponseRedirect(redirect_url)
示例14: try_login
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def try_login(self, identity_url, ask_for=None):
"""This tries to login with the given identity URL. This function
must be called from the login_handler. The `ask_for` parameter can
be a set of values to be asked from the openid provider.
The following strings can be used in the `ask_for` parameter:
``aim``, ``blog``, ``country``, ``dob`` (date of birth), ``email``,
``fullname``, ``gender``, ``icq``, ``image``, ``jabber``, ``language``,
``msn``, ``nickname``, ``phone``, ``postcode``, ``skype``,
``timezone``, ``website``, ``yahoo``
"""
if ask_for and __debug__:
for key in ask_for:
if key not in ALL_KEYS:
raise ValueError('invalid key %r' % key)
try:
oidutil.log("self.store_factory() :" + str(self.store_factory))
consumer = Consumer(SessionWrapper(self), self.store_factory())
auth_request = consumer.begin(identity_url)
if ask_for:
self.attach_reg_info(auth_request, ask_for)
except discover.DiscoveryFailure:
self.signal_error(u'The OpenID was invalid')
return redirect(self.get_current_url())
trust_root = request.host_url
return redirect(auth_request.redirectURL(request.host_url,
self.get_success_url()))
示例15: link_google
# 需要导入模块: from openid.consumer.consumer import Consumer [as 别名]
# 或者: from openid.consumer.consumer.Consumer import begin [as 别名]
def link_google(self, registration):
openid_session = session.get("openid_session", {})
openid_store = None # stateless
cons = Consumer(openid_session, openid_store)
GOOGLE_OPENID = 'https://www.google.com/accounts/o8/id'
try:
authrequest = cons.begin(GOOGLE_OPENID)
except DiscoveryFailure:
h.flash(_('Authentication failed, please try again.'))
redirect(registration.url(action='personal_info'))
ax_req = ax.FetchRequest()
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/first',
alias='firstname', required=True))
ax_req.add(ax.AttrInfo('http://axschema.org/namePerson/last',
alias='lastname', required=True))
ax_req.add(ax.AttrInfo('http://schema.openid.net/contact/email',
alias='email', required=True))
authrequest.addExtension(ax_req)
session['openid_session'] = openid_session
session.save()
realm = url(controller='home', action='index', qualified=True)
return_to = registration.url(action='google_verify', qualified=True)
redirect(authrequest.redirectURL(realm, return_to))