【问题标题】:Nokia-Withings Oauth2 Get Authentification CodeNokia-Withings Oauth2 获取验证码
【发布时间】:2019-01-12 20:25:03
【问题描述】:

我很难让 Nokia-Withings OAuth2 流程与在 localhost 上运行的烧瓶应用程序一起工作。我确保在 /etc/hosts 中有一个从回调 url (nokia.velometria.com) 到 127.0.0.1 的重定向,以确保所有回调请求都返回到应用程序。

发生的情况是,对诺基亚 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=授权2

[2018-08-05 22:24:28,136] nokia_callback 中的信息:标头:{'日期':'Sun,2018 年 8 月 5 日 20:24:25 GMT','服务器':'Apache','内容-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 - 这绝对不是我所期望的行为。

关于如何让它工作的任何想法?

【问题讨论】:

    标签: withings


    【解决方案1】:

    我遇到了类似的问题。基本上https://account.withings.com/oauth2_user/authorize2 url 应该由用户在浏览器窗口中打开。 (因此您可以在另一个弹出窗口或 iframe 中打开它。) 该网站将要求应用程序权限,并在需要时要求用户登录。

    用户点击你的应用有权使用他的数据后,网站会重定向到你的带参数的uri回调。

    所以你的http://nokia.velometria.com/ 应该监听 API 给出的请求参数。

    【讨论】:

      猜你喜欢
      • 2019-11-14
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 2022-09-28
      • 2015-12-11
      • 2016-12-07
      • 2017-11-28
      • 1970-01-01
      相关资源
      最近更新 更多