【发布时间】:2019-01-07 05:28:59
【问题描述】:
我正在尝试创建一个快速的网络应用程序来验证用户的 Yahoo 帐户,但我无法获得“用户批准”。
就我个人而言,每次我去外部网站并且必须进行身份验证时,我通常都会登录我的帐户。这似乎将我重定向到一个页面并要求输入代码。我不知道我需要提供什么代码才能进行身份验证。如果我不知道,我的用户肯定不会!我正在构建一个烧瓶应用程序,并尝试围绕this repo 建模我的代码。
我已经为雅虎添加了一些代码,但似乎无法连接这些点。下面 oauth.py 文件中的新 YahooSignIn 子类:
class YahooSignIn(OAuthSignIn):
def __init__(self):
super(YahooSignIn, self).__init__('yahoo')
self.service = OAuth2Service(
name='yahoo',
consumer_id=self.consumer_id,
consumer_secret=self.consume_secret,
authorize_url='https://api.login.yahoo.com/oauth/v2/request_auth',
access_token_url='https://api.login.yahoo.com/oauth/v2/get_token',
base_url='http://fantasysports.yahooapis.com/'
)
def authorize(self):
return redirect(self.service.get_authorize_url(
scope='email',
response_type='code',
redirect_uri=self.get_callback_url())
)
def callback(self):
def decode_json(payload):
return json.loads(payload.decode('utf-8'))
if 'code' not in request.args:
return None, None, None
oauth_session = self.service.get_auth_session(
data={'code': request.args['code'],
'grant_type': 'authorization_code',
'redirect_uri': self.get_callback_url()},
decoder=decode_json
)
me = oauth_session.get('me?fields=id,email').json()
return (
'yahoo$' + me['id'],
me.get('email').split('@')[0],
me.get('email')
)
唯一的其他更改是对 index.html 页面添加了一个带有“yahoo”参数的附加链接
<p><a href="{{ url_for('oauth_authorize', provider='yahoo') }}">Login with Yahoo</a></p>
任何帮助都将不胜感激,因为在过去的两个晚上,这个问题一直困扰着我,我很想摆脱这个问题!
【问题讨论】:
标签: python flask oauth-2.0 yahoo