本文整理匯總了Python中flask.ext.oauth.OAuth類的典型用法代碼示例。如果您正苦於以下問題:Python OAuth類的具體用法?Python OAuth怎麽用?Python OAuth使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了OAuth類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: init_oauth
def init_oauth(app):
global o_twitter, o_facebook, oauth_authorized
oauth = OAuth()
o_twitter = oauth.remote_app('twitter',
base_url='https://api.twitter.com/1/',
request_token_url='https://api.twitter.com/oauth/request_token',
access_token_url='https://api.twitter.com/oauth/access_token',
authorize_url='https://api.twitter.com/oauth/authenticate',
consumer_key=app.config["OAUTH_TWITTER_CONSUMER_KEY"],
consumer_secret=app.config["OAUTH_TWITTER_CONSUMER_SECRET"],
access_token_method='POST'
)
user.add_url_rule('/oauth/twitter', "twitter_authorized", o_twitter.authorized_handler(twitter_authorized))
o_twitter.tokengetter(oauth_token)
o_facebook = oauth.remote_app('facebook',
base_url='https://graph.facebook.com/',
request_token_url=None,
access_token_url='/oauth/access_token',
authorize_url=app.config["OAUTH_FACEBOOK_SITE_URL"],
consumer_key=app.config["OAUTH_FACEBOOK_CONSUMER_KEY"],
consumer_secret=app.config["OAUTH_FACEBOOK_CONSUMER_SECRET"],
request_token_params={'scope': 'email'}
)
user.add_url_rule('/oauth/facebook', "facebook_authorized", o_facebook.authorized_handler(facebook_authorized))
o_facebook.tokengetter(oauth_token)
示例2: __init__
def __init__(self, name, title, key, secret, access_key, access_secret, at_login=True, priority=True, icon=None):
self.name = name
self.title = title
self.at_login = at_login
self.priority = priority
self.icon = icon
self.consumer_key = key
self.consumer_secret = secret
self.access_key = access_key
self.access_secret = access_secret
oauth = OAuth()
twitter = oauth.remote_app(
"twitter",
base_url="https://api.twitter.com/1/",
request_token_url="https://api.twitter.com/oauth/request_token",
access_token_url="https://api.twitter.com/oauth/access_token",
authorize_url="https://api.twitter.com/oauth/authenticate",
consumer_key=key,
consumer_secret=secret,
)
twitter.tokengetter(lambda token=None: None) # We have no use for tokengetter
self.callback = twitter_exception_handler(twitter.authorized_handler(self.unwrapped_callback))
self.twitter = twitter
示例3: oauth_app
def oauth_app(self, base_url='https://api.twitter.com/1.1/'):
oauth = OAuth()
twitter = oauth.remote_app(
'twitter',
base_url='',
request_token_url='https://api.twitter.com/oauth/request_token',
access_token_url='https://api.twitter.com/oauth/access_token',
authorize_url='https://api.twitter.com/oauth/authenticate',
consumer_key=self.app.config.get('TWITTER_CONSUMER_KEY'),
consumer_secret=self.app.config.get('TWITTER_CONSUMER_SECRET'),
)
twitter.tokengetter(self.tokengetter)
return twitter
示例4: get_github_oauth_client
def get_github_oauth_client(self, scope='', token='github_oauth_token'):
"""Returns a instance of Github OAuth
"""
if not all([self.github_id, self.github_secret]):
current_app.logger.error("Github api settings are missing")
flash(_("Github login is not available at the moment"))
return None
oauth = OAuth()
github = oauth.remote_app('github',
base_url='https://github.com',
request_token_url=None,
access_token_url='/login/oauth/access_token',
authorize_url='/login/oauth/authorize',
consumer_key=self.github_id,
consumer_secret=self.github_secret,
request_token_params={'scope': scope},
access_token_method="POST",
)
github.tokengetter_func = lambda *a: session.get(token)
return github
示例5: init_github_oauth_app
def init_github_oauth_app(github_client_id, github_client_secret):
github_oauth_app = OAuth().remote_app(
"github",
base_url="https://github.com",
request_token_url=None,
access_token_url="https://github.com/login/oauth/access_token",
authorize_url="https://github.com/login/oauth/authorize",
consumer_key=github_client_id,
consumer_secret=github_client_secret,
request_token_params={"scope": "repo"},
)
github_oauth_app.tokengetter(lambda token=None: None)
# Hack to avoid the following error:
# SSLHandshakeError: [Errno 1] _ssl.c:504: error:14090086:SSL
# routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
# See http://stackoverflow.com/a/10393381 for details
github_oauth_app._client.ca_certs = certifi.where()
# Store OAuth app at the blueprint object to make it available
# to the view functions
bp.github_oauth_app = github_oauth_app
示例6: config_web
def config_web(args):
from flask import Flask
from flask.ext.login import LoginManager
from flask.ext.oauth import OAuth
global app
app = Flask('wikimetrics')
web_config = create_object_from_text_config_file(args.web_config)
app.config.from_object(web_config)
if args.override_config:
web_config = create_object_from_text_config_file(args.override_config)
app.config.from_object(web_config)
global login_manager
login_manager = LoginManager()
login_manager.init_app(app)
global google
oauth = OAuth()
google = oauth.remote_app(
'google',
base_url=app.config['GOOGLE_BASE_URL'],
authorize_url=app.config['GOOGLE_AUTH_URI'],
request_token_url=None,
request_token_params={
'scope': app.config['GOOGLE_AUTH_SCOPE'],
'response_type': 'code',
},
access_token_url=app.config['GOOGLE_TOKEN_URI'],
access_token_method='POST',
access_token_params={
'grant_type':
'authorization_code'
},
consumer_key=app.config['GOOGLE_CLIENT_ID'],
consumer_secret=app.config['GOOGLE_CLIENT_SECRET'],
)
示例7: Flask
from collections import defaultdict
import feedparser
from mongo_stuff import MongoLib
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
app = Flask(__name__)
# import config from $APP_CONFIG file
app.config.from_envvar("APP_CONFIG") # export APP_CONFIG=/path/to/settings.cfg
app.secret_key = app.config["SECRET_KEY"]
oauth = OAuth()
google = oauth.remote_app(
"google",
base_url="https://www.google.com/accounts/",
authorize_url="https://accounts.google.com/o/oauth2/auth",
request_token_url=None,
request_token_params={
"scope": "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile http://www.google.com/reader/api/0/subscription/list",
"response_type": "code",
},
access_token_url="https://accounts.google.com/o/oauth2/token",
access_token_method="POST",
access_token_params={"grant_type": "authorization_code"},
consumer_key=app.config["GOOGLE_CLIENT_ID"],
consumer_secret=app.config["GOOGLE_CLIENT_SECRET"],
)
示例8: OAuth
from urllib2 import urlopen, URLError
from urlparse import parse_qs
from flask import request, session, redirect, flash, url_for, json
from flask.ext.oauth import OAuth, OAuthException # OAuth 1.0a
from httplib import BadStatusLine
from coaster import valid_username
from coaster.views import get_next_url
from lastuserapp import app
from lastuserapp.models import db, UserExternalId, UserEmail, User
from lastuserapp.views.helpers import login_internal, register_internal
from lastuserapp.utils import get_gravatar_md5sum
# OAuth 1.0a handlers
oauth = OAuth()
twitter = oauth.remote_app('twitter',
base_url='https://api.twitter.com/1/',
request_token_url='https://api.twitter.com/oauth/request_token',
access_token_url='https://api.twitter.com/oauth/access_token',
authorize_url='https://api.twitter.com/oauth/authenticate',
consumer_key=app.config.get('OAUTH_TWITTER_KEY'),
consumer_secret=app.config.get('OAUTH_TWITTER_SECRET'),
)
def get_extid_token(service):
useridinfo = session.get('userid_external')
if useridinfo:
if service != useridinfo.get('service'):
return None
示例9: SeaSurf
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask.ext.seasurf import SeaSurf
from flask.ext.oauth import OAuth
from vksunshine.config import VK_BASE_URL, VK_ACCESS_TOKEN_URL, VK_AUTHORIZE_URL, \
VK_REQUEST_TOKEN_PARAMS, VK_CONSUMER_KEY, VK_CONSUMER_SECRET
__all__ = ['csrf', 'oauth_manager', 'vkontakte']
csrf = SeaSurf()
oauth_manager = OAuth()
vkontakte = oauth_manager.remote_app('vkontakte',
base_url=VK_BASE_URL,
authorize_url=VK_AUTHORIZE_URL,
request_token_url=None,
request_token_params=VK_REQUEST_TOKEN_PARAMS,
access_token_url=VK_ACCESS_TOKEN_URL,
consumer_key=VK_CONSUMER_KEY,
consumer_secret=VK_CONSUMER_SECRET)
示例10: Mailer
ProfileForm,
MemoryForm,
LANGUAGE_CHOICES,
STATES,
BENEFICIARY_CATEGORY)
from ..service import signup as signup_service
from ..service import user as user_service
from ..service import donate as donate_service
from flask_user import current_user, login_required, roles_required
from ..helpers import allowed_file
from ..models import db, BaseNameMixin, BaseMixin
from ..mailer import Mailer
mailer = Mailer()
# Facebook requirements
oauth = OAuth()
facebook = oauth.remote_app(
'facebook',
request_token_url=None,
base_url='https://graph.facebook.com/',
access_token_url='/oauth/access_token',
authorize_url='https://www.facebook.com/dialog/oauth',
consumer_key=app.config.get('FACEBOOK_CONSUMER_KEY'),
consumer_secret=app.config.get('FACEBOOK_CONSUMER_SECRET'),
request_token_params={'scope': 'email'})
@facebook.tokengetter
def get_facebook_token():
return session.get('facebook_token')
示例11: Flask
import requests
import os
import opml
from orm import User, Anonymous
app = Flask(__name__)
# import config from $APP_CONFIG file
app.config.from_envvar('APP_CONFIG')
app.secret_key = app.config['SECRET_KEY']
# google oauth2 setup
oauth = OAuth()
google = oauth.remote_app('google',
base_url='https://www.google.com/accounts/',
authorize_url='https://accounts.google.com/o/oauth2/auth',
request_token_url=None,
request_token_params= {'scope': 'https://www.googleapis.com/auth/userinfo.email \
https://www.googleapis.com/auth/userinfo.profile http://www.google.com/reader/api/0/subscription/list',
'response_type': 'code'},
access_token_url='https://accounts.google.com/o/oauth2/token',
access_token_method='POST',
access_token_params={'grant_type': 'authorization_code'},
consumer_key=app.config['GOOGLE_CLIENT_ID'],
consumer_secret=app.config['GOOGLE_CLIENT_SECRET'])
# login manager
login_manager = LoginManager()
示例12: OAuth
from flask.ext.mail import Mail, Message
from flaskext.bcrypt import Bcrypt
from flask_debugtoolbar import DebugToolbarExtension
from flask.ext.oauth import OAuth
from sqlalchemy.orm import aliased, contains_eager
from datetime import datetime
from wtforms import Form
oauth = OAuth()
facebook = oauth.remote_app('facebook',
base_url='https://graph.facebook.com/',
request_token_url=None,
access_token_url='/oauth/access_token',
authorize_url='https://www.facebook.com/dialog/oauth',
consumer_key='233700133415330',
consumer_secret='1d28dccf888bb41517693847b1d335d8',
request_token_params={'scope': 'email'}
)
toolbar = DebugToolbarExtension(app)
bcrypt = Bcrypt()
示例13: SQLAlchemy
db = SQLAlchemy(app)
"""
In models.py we import 'db' from 'app'. So, we have
circular dependency here. Import 'Account' after 'db'
to temporarily resolve this.
"""
from models import Account
###########################
oauth = OAuth()
facebook = oauth.remote_app('facebook',
base_url = 'https://graph.facebook.com/',
request_token_url = None,
access_token_url = '/oauth/access_token',
authorize_url = 'https://www.facebook.com/dialog/oauth',
consumer_key = settings.FACEBOOK_APP_ID,
consumer_secret = settings.FACEBOOK_APP_SECRET,
request_token_params = { 'scope': settings.FACEBOOK_APP_SCOPE }
)
###########################
示例14: config_web
def config_web(args):
from flask import Flask, request, json
from flask.ext.login import LoginManager
from flask.ext.oauth import (
OAuth, OAuthRemoteApp, OAuthException, get_etree
)
from werkzeug import url_decode, parse_options_header
import flask.ext.oauth as nasty_patch_to_oauth
global app
app = Flask('wikimetrics')
# note absolute_path does not change on the life of the application
app.absolute_path_to_app_root = get_absolute_path()
# TODO do we need this config to be created like an object instead of a dictionary?
web_config = create_object_from_text_config_file(args.web_config)
# if args.override_config:
# override_config = create_object_from_text_config_file(args.override_config)
# TODO override one obj with other, can we use dict?
app.config.from_object(web_config)
version, latest = get_wikimetrics_version()
app.config['WIKIMETRICS_LATEST'] = latest
app.config['WIKIMETRICS_VERSION'] = version
# configure logging
if not app.config['DEBUG']:
import logging
import sys
app.logger.addHandler(logging.StreamHandler(stream=sys.stderr))
global login_manager
login_manager = LoginManager()
login_manager.init_app(app)
# TODO, this does not need to be a
# global, could be stored in flask application context
global google
oauth = OAuth()
google = oauth.remote_app(
'google',
base_url=app.config['GOOGLE_BASE_URL'],
authorize_url=app.config['GOOGLE_AUTH_URI'],
request_token_url=None,
request_token_params={
'scope': app.config['GOOGLE_AUTH_SCOPE'],
'response_type': 'code',
},
access_token_url=app.config['GOOGLE_TOKEN_URI'],
access_token_method='POST',
access_token_params={
'grant_type':
'authorization_code'
},
consumer_key=app.config['GOOGLE_CLIENT_ID'],
consumer_secret=app.config['GOOGLE_CLIENT_SECRET'],
)
def better_parse_response(resp, content, strict=False):
ct, options = parse_options_header(resp['content-type'])
if ct in ('application/json', 'text/javascript'):
try:
return json.loads(content)
# handle json decode errors from parse_response
# this is useful in the identify call because the response is
# 'application/json' but the content is encoded
except:
return content
elif ct in ('application/xml', 'text/xml'):
# technically, text/xml is ascii based but because many
# implementations get that wrong and utf-8 is a superset
# of utf-8 anyways, so there is not much harm in assuming
# utf-8 here
charset = options.get('charset', 'utf-8')
return get_etree().fromstring(content.decode(charset))
elif ct != 'application/x-www-form-urlencoded':
if strict:
return content
charset = options.get('charset', 'utf-8')
return url_decode(content, charset=charset).to_dict()
# TODO: Even worse, definitely patch upstream or consider switching to rauth
nasty_patch_to_oauth.parse_response = better_parse_response
# TODO: patch upstream
# NOTE: a million thanks to Merlijn_van_Deen, author of
# https://wikitech.wikimedia.org/wiki/Setting_up_Flask_cgi_app_as_a_tool/OAuth
class MediaWikiOAuthRemoteApp(OAuthRemoteApp):
def handle_oauth1_response(self):
"""
Handles an oauth1 authorization response. The return value of
this method is forwarded as the first argument to the handling
view function.
"""
client = self.make_client()
resp, content = client.request(
'{0}&oauth_verifier={1}'.format(
self.expand_url(self.access_token_url),
request.args['oauth_verifier'],
),
#.........這裏部分代碼省略.........
示例15: Acode
class Acode(Base):
__tablename__ = 'acode'
id = Column(Integer, primary_key=True)
code = Column(String)
date_created = Column(DateTime, default=datetime.utcnow)
def __init__(self, code):
self.code = code
def init_db():
Base.metadata.create_all(bind=engine)
def drop_db():
Base.metadata.drop_all(bind=engine)
oauth = OAuth()
vk = oauth.remote_app('vkontakte',
base_url='https://api.vk.com/method/',
request_token_url=None,
access_token_url='https://api.vk.com/oauth/token',
authorize_url='http://api.vk.com/oauth/authorize',
consumer_key='2904906',
consumer_secret='xpyuJye6NozdTazuuRvM',
request_token_params={'scope': 'offline'}
)
@app.before_request
def before_request():
g.code=getattr(g,'code',None)
if not g.code: