我确实很难让 Nokia-Withings OAuth2 流程与在本地主机上运行的烧瓶应用程序一起工作。我已确保在 /etc/hosts 中有从回调 url (nokia.velometria.com) 到 127.0.0.1 的重定向,以确保所有回调请求都返回到应用程序。
发生的情况是,对 nokia authorize2的原始 get 请求会自动重定向到account_login,并且永远不会将带有代码的请求返回到指定的回调 url (nokia.velometria.com/code.
这是我使用的烧瓶代码:
from flask import Flask, request
import requests
import os
app = Flask(__name__)
@app.route("/code", methods=["GET"])
def nokia_code():
"""I expect the url with a code to be sent here"""
return request.get_data()
@app.route("/", methods=["GET", "POST"])
def nokia_callback():
"""OAuth 2.0 - Get your authentication code"""
if request.method == "POST": # just for debugging
app.logger.info("POST request data: {}".format(request.get_data()))
app.logger.info("POST request path: {}".format(request.path))
return "post"
else: # the actual GET request
url = "https://account.health.nokia.com/oauth2_user/authorize2"
client_id = os.getenv("NOKIA_CLIENT_ID", None)
params = {
"response_type": "code",
"client_id": client_id,
"state": "/",
"scope": "user.info",
"redirect_url": "http://nokia.velometria.com/code"
}
r = requests.get(url, params=params)
app.logger.info("url: {}".format(r.url))
app.logger.info("headers: {}".format(r.headers))
app.logger.info("history: {}".format(r.history))
return r.text
if __name__ == "__main__":
app.run(debug=True)
这是我得到的烧瓶日志:
[2018-08-05 22:24:28,136] nokia_callback 中的信息:url:https ://account.health.nokia.com/oauth2_user/account_login?response_type =code&client_id= ***&state=%2F&scope=user.info&redirect_url= http%3A%2F%2Fnokia.velometria.com%2Fcode&b=authorize2
[2018-08-05 22:24:28,136] nokia_callback 中的信息:标头:{'Date':'Sun,2018 年 8 月 5 日 20:24:25 GMT','Server':'Apache','Content-Security- Policy':“frame-ancestors 'self ' https://dashboard.health.nokia.com/”,'Strict-Transport-Security':'max-age=2592000','X-XSS-Protection':'1 ','X-Content-Type-Options':'nosniff','Referrer-Policy':'strict-origin-when-cross-origin','Vary':'Accept-Encoding','Content-Encoding': 'gzip', 'X-Frame-Options': 'ALLOW-FROM https://dashboard.health.nokia.com/ ', 'Content-Length': '2373', 'Content-Type': 'text/html ;charset=UTF-8'}
[2018-08-05 22:24:28,136] nokia_callback 中的信息:历史记录:[] 127.0.0.1 - - [05/Aug/2018 22:24:28] “GET / HTTP/1.1”200 - 127.0.0.1 - - [05/Aug/2018 22:24:28] “GET /min/g=baseCSS,blockv4CSS&2ef1f384 HTTP/1.1”404 - 127.0.0.1 - - [05/Aug/2018 22:24:28] “GET /min /g=basev4JS&2ef1f384 HTTP/1.1" 404 - 127.0.0.1 - - [05/Aug/2018 22:24:28] "GET /min/g=basev4JS&2ef1f384 HTTP/1.1" 404 -
[2018-08-05 22:24:33,318] nokia_callback 中的信息:POST 请求数据:b'email= &password= &is_admin=f&csrf_token=***'
[2018-08-05 22:24:33,318] nokia_callback 中的信息:POST 请求路径:/127.0.0.1 - - [05/Aug/2018 22:24:33] “POST / HTTP/1.1”200 -
请注意,请求 url 自动从 authorize2 重定向到 account_login,然后使用帐户凭据在烧瓶服务器上调用 POST - 这绝对不是我所期待的行为。
关于如何让它工作的任何想法?