本文整理汇总了Python中util.oauth_starter函数的典型用法代码示例。如果您正苦于以下问题:Python oauth_starter函数的具体用法?Python oauth_starter怎么用?Python oauth_starter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了oauth_starter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_oauth_flow
def start_oauth_flow(self, feature):
starter = util.oauth_starter(
oauth_flickr.StartHandler, feature=feature
).to(
'/flickr/add', scopes='write' if feature == 'publish' else 'read'
)
return starter(self.request, self.response).post()
示例2: finish_oauth_flow
def finish_oauth_flow(self, auth_entity, state):
"""Adds or deletes a FacebookPage, or restarts OAuth to get publish permissions.
Args:
auth_entity: FacebookAuth
state: encoded state string
"""
if auth_entity is None:
auth_entity_key = util.get_required_param(self, "auth_entity_key")
auth_entity = ndb.Key(urlsafe=auth_entity_key).get()
if state is None:
state = self.request.get("state")
state_obj = self.decode_state_parameter(state)
id = state_obj.get("id") or self.request.get("id")
if id and id != auth_entity.key.id():
auth_entity = auth_entity.for_page(id)
auth_entity.put()
source = self.maybe_add_or_delete_source(FacebookPage, auth_entity, state)
# If we were already signed up for publish, we had an access token with publish
# permissions. If we then go through the listen signup flow, we'll get a token
# with just the listen permissions. In that case, do the whole OAuth flow again
# to get a token with publish permissions again.
feature = state_obj.get("feature")
if source is not None and feature == "listen" and "publish" in source.features:
logging.info("Restarting OAuth flow to get publish permissions.")
source.features.remove("publish")
source.put()
start = util.oauth_starter(oauth_facebook.StartHandler, feature="publish", id=id)
restart = start.to("/facebook/oauth_handler", scopes=PUBLISH_SCOPES)
restart(self.request, self.response).post()
示例3: post
def post(self):
features = self.request.get('feature')
features = features.split(',') if features else []
starter = util.oauth_starter(oauth_instagram.StartHandler).to(
'/instagram/oauth_callback',
# http://instagram.com/developer/authentication/#scope
scopes='likes comments' if 'publish' in features else None)
starter(self.request, self.response).post()
示例4: post
def post(self):
features = self.request.get('feature')
features = features.split(',') if features else []
starter = util.oauth_starter(oauth_facebook.StartHandler).to(
'/facebook/oauth_handler', scopes=sorted(set(
(LISTEN_SCOPES if 'listen' in features else []) +
(PUBLISH_SCOPES if 'publish' in features else []))))
starter(self.request, self.response).post()
示例5: post
def post(self):
# pass explicit 'write' instead of None for publish so that oauth-dropins
# (and tweepy) don't use signin_with_twitter ie /authorize. this works
# around a twitter API bug: https://dev.twitter.com/discussions/21281
access_type = ('read' if util.get_required_param(self, 'feature')
== 'listen' else 'write')
handler = util.oauth_starter(oauth_twitter.StartHandler).to(
'/twitter/add', access_type=access_type)(self.request, self.response)
return handler.post()
示例6: post
def post(self):
features = self.request.get("feature")
features = features.split(",") if features else []
starter = util.oauth_starter(oauth_facebook.StartHandler).to(
"/facebook/oauth_handler",
scopes=sorted(
set((LISTEN_SCOPES if "listen" in features else []) + (PUBLISH_SCOPES if "publish" in features else []))
),
)
starter(self.request, self.response).post()
示例7: post
def post(self):
ia_start = util.oauth_starter(indieauth.StartHandler).to('/instagram/callback')(
self.request, self.response)
try:
self.redirect(ia_start.redirect_url(me=util.get_required_param(self, 'user_url')))
except Exception as e:
if util.is_connection_failure(e) or util.interpret_http_exception(e)[0]:
self.messages.add("Couldn't fetch your web site: %s" % e)
return self.redirect('/')
raise
示例8: start_oauth_flow
def start_oauth_flow(self, feature):
"""Redirects to Twitter's OAuth endpoint to start the OAuth flow.
Args:
feature: 'listen' or 'publish'
"""
features = feature.split(',') if feature else []
assert all(f in models.Source.FEATURES for f in features)
# pass explicit 'write' instead of None for publish so that oauth-dropins
# (and tweepy) don't use signin_with_twitter ie /authorize. this works
# around a twitter API bug: https://dev.twitter.com/discussions/21281
access_type = 'write' if 'publish' in features else 'read'
handler = util.oauth_starter(oauth_twitter.StartHandler, feature=feature).to(
'/twitter/add', access_type=access_type)(self.request, self.response)
return handler.post()
示例9: finish_oauth_flow
def finish_oauth_flow(self, auth_entity, state):
"""Adds or deletes a :class:`FacebookPage`, or restarts OAuth to get publish
permissions.
Args:
auth_entity: :class:`oauth_dropins.facebook.FacebookAuth`
state: encoded state string
"""
if auth_entity is None:
auth_entity_key = self.request.get('auth_entity_key')
if auth_entity_key:
auth_entity = ndb.Key(urlsafe=auth_entity_key).get()
if state is None:
state = self.request.get('state')
state_obj = util.decode_oauth_state(state) if state else {}
id = state_obj.get('id') or self.request.get('id')
if id and auth_entity and id != auth_entity.key.id():
auth_entity = auth_entity.for_page(id)
if auth_entity:
auth_entity.put()
source = self.maybe_add_or_delete_source(FacebookPage, auth_entity, state)
# If we were already signed up for publish, we had an access token with publish
# permissions. If we then go through the listen signup flow, we'll get a token
# with just the listen permissions. In that case, do the whole OAuth flow again
# to get a token with publish permissions again.
feature = state_obj.get('feature')
if source is not None and feature == 'listen' and 'publish' in source.features:
logging.info('Restarting OAuth flow to get publish permissions.')
source.features.remove('publish')
source.put()
start = util.oauth_starter(oauth_facebook.StartHandler,
feature='publish', id=id)
restart = start.to('/facebook/oauth_handler', scopes=PUBLISH_SCOPES)
restart(self.request, self.response).post()
# ask the user for their web site if we don't already have one.
if source and not source.domains:
self.redirect('/edit-websites?' + urllib.urlencode({
'source_key': source.key.urlsafe(),
}))
示例10: ConfirmSelfHosted
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(template.render(
'templates/confirm_self_hosted_wordpress.html',
{'auth_entity_key': auth_entity.key.urlsafe(), 'state': state}))
return
self.maybe_add_or_delete_source(WordPress, auth_entity, state)
class ConfirmSelfHosted(util.Handler):
def post(self):
self.maybe_add_or_delete_source(
WordPress,
ndb.Key(urlsafe=util.get_required_param(self, 'auth_entity_key')).get(),
util.get_required_param(self, 'state'))
class SuperfeedrNotifyHandler(superfeedr.NotifyHandler):
SOURCE_CLS = WordPress
application = webapp2.WSGIApplication([
('/wordpress/start', util.oauth_starter(oauth_wordpress.StartHandler).to(
'/wordpress/add')),
('/wordpress/confirm', ConfirmSelfHosted),
# This handles both add and delete. (WordPress.com only allows a single
# OAuth redirect URL.)
('/wordpress/add', AddWordPress),
('/wordpress/notify/(.+)', SuperfeedrNotifyHandler),
], debug=appengine_config.DEBUG)
示例11: AddFacebookPage
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(
template.render('templates/choose_facebook.html', vars))
class AddFacebookPage(util.Handler):
def post(self):
state = util.get_required_param(self, 'state')
id = util.get_required_param(self, 'id')
auth_entity_key = util.get_required_param(self, 'auth_entity_key')
auth_entity = ndb.Key(urlsafe=auth_entity_key).get()
if id != auth_entity.key.id():
auth_entity = auth_entity.for_page(id)
auth_entity.put()
self.maybe_add_or_delete_source(FacebookPage, auth_entity, state)
application = webapp2.WSGIApplication([
# OAuth scopes are set in listen.html and publish.html
('/facebook/start', util.oauth_starter(oauth_facebook.StartHandler).to(
'/facebook/oauth_handler')),
('/facebook/oauth_handler', OAuthCallback),
('/facebook/add', AddFacebookPage),
('/facebook/delete/finish', oauth_facebook.CallbackHandler.to('/delete/finish')),
('/facebook/publish/start', oauth_facebook.StartHandler.to(
'/publish/facebook/finish')),
], debug=appengine_config.DEBUG)
示例12: AddTumblr
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write(template.render('templates/choose_blog.html', vars))
class AddTumblr(util.Handler):
def post(self):
auth_entity_key = util.get_required_param(self, 'auth_entity_key')
self.maybe_add_or_delete_source(
Tumblr,
ndb.Key(urlsafe=auth_entity_key).get(),
util.get_required_param(self, 'state'),
blog_name=util.get_required_param(self, 'blog'),
)
class SuperfeedrNotifyHandler(superfeedr.NotifyHandler):
SOURCE_CLS = Tumblr
application = webapp2.WSGIApplication([
# Tumblr doesn't seem to use scope
# http://www.tumblr.com/docs/en/api/v2#oauth
('/tumblr/start', util.oauth_starter(oauth_tumblr.StartHandler).to(
'/tumblr/choose_blog')),
('/tumblr/choose_blog', ChooseBlog),
('/tumblr/add', AddTumblr),
('/tumblr/delete/finish', oauth_tumblr.CallbackHandler.to('/delete/finish')),
('/tumblr/notify/(.+)', SuperfeedrNotifyHandler),
], debug=appengine_config.DEBUG)
示例13: ConfirmSelfHosted
self.maybe_add_or_delete_source(WordPress, auth_entity, state)
class ConfirmSelfHosted(util.Handler):
def post(self):
self.maybe_add_or_delete_source(
WordPress,
ndb.Key(urlsafe=util.get_required_param(self, "auth_entity_key")).get(),
util.get_required_param(self, "state"),
)
class SuperfeedrNotifyHandler(superfeedr.NotifyHandler):
SOURCE_CLS = WordPress
application = webapp2.WSGIApplication(
[
# wordpress.com doesn't seem to use scope
# https://developer.wordpress.com/docs/oauth2/
("/wordpress/start", util.oauth_starter(oauth_wordpress.StartHandler).to("/wordpress/add")),
("/wordpress/confirm", ConfirmSelfHosted),
# This handles both add and delete. (WordPress.com only allows a single
# OAuth redirect URL.)
("/wordpress/add", AddWordPress),
("/wordpress/notify/(.+)", SuperfeedrNotifyHandler),
],
debug=appengine_config.DEBUG,
)
示例14: super
"""
return super(GooglePlusPage, self).canonicalize_syndication_url(
util.follow_redirects(url).url)
class OAuthCallback(util.Handler):
"""OAuth callback handler.
Both the add and delete flows have to share this because Google+'s
oauth-dropin doesn't yet allow multiple callback handlers. :/
"""
def get(self):
auth_entity_str_key = util.get_required_param(self, 'auth_entity')
state = self.request.get('state')
if not state:
# state doesn't currently come through for G+. not sure why. doesn't
# matter for now since we don't plan to implement publish for G+.
state = self.construct_state_param_for_add(feature='listen')
auth_entity = ndb.Key(urlsafe=auth_entity_str_key).get()
self.maybe_add_or_delete_source(GooglePlusPage, auth_entity, state)
application = webapp2.WSGIApplication([
# OAuth scopes are set in listen.html and publish.html
('/googleplus/start', util.oauth_starter(oauth_googleplus.StartHandler).to(
'/googleplus/oauth2callback')),
('/googleplus/oauth2callback', oauth_googleplus.CallbackHandler.to('/googleplus/add')),
('/googleplus/add', OAuthCallback),
('/googleplus/delete/start', oauth_googleplus.StartHandler.to('/googleplus/oauth2callback')),
], debug=appengine_config.DEBUG)
示例15: OAuthStartHandler
sent=['http://a/link'],
)]
class OAuthStartHandler(oauth_handlers.StartHandler):
"""Stand-in for the oauth-dropins StartHandler, redirects to
a made-up silo url
"""
def redirect_url(self, state=None):
logging.debug('oauth handler redirect')
return 'http://fake/auth/url?' + urllib.urlencode({
'redirect_uri': self.to_url(state),
})
FakeStartHandler = util.oauth_starter(OAuthStartHandler).to('/fakesource/add')
class FakeAddHandler(util.Handler):
"""Handles the authorization callback when handling a fake source
"""
auth_entity = FakeAuthEntity(user_json=json.dumps({
'id': '0123456789',
'name': 'Fake User',
'url': 'http://fakeuser.com/',
}))
@staticmethod
def with_auth(auth):
class HandlerWithAuth(FakeAddHandler):
auth_entity = auth