注册 Fitbit 时的自定义 ID

Custom ID when registering Fitbit

对于我的系统,我的用户拥有我提供给他们的唯一 ID (participant_id)。

我有一个 Flask 服务器,可以用 Fitbit 注册我的用户。

@app.route('/fitbit_authorize')
def homepage(): #probably need to send participant_id here
    return '<a href="%s">Authenticate with fitbit</a>' % FITBIT_AUTHORIZATION_URL

Fitbit 向以下地址发送关于我的参与者注册成功的 post 请求,我从中获得他们的用户 access/refresh oauth 令牌:

@app.route('/fitbit_callback')
def fitbit_callback():
    error = request.args.get('error', '')
    if error:
        return "Error: " + error
    state = request.args.get('state', '')
    code = request.args.get('code')
    token = fitbit_access.get_full_token(code)

我想知道如何在回调中检索授权人的原始 ID (participant_id)。无论如何,我是否可以在 fitbit 授权过程中传递其他信息,或者我检索他们的最佳方式是什么 participant_id?

好问题。

Oauth2允许您在授权请求中包含状态信息---您可以在状态参数中包含participant_idhttps://dev.fitbit.com/build/reference/web-api/oauth2/

state: Provides any state that might be useful to your application when the user is redirected back to your application. This parameter will be added to the redirect URI exactly as your application specifies. Fitbit strongly recommend including an anti-forgery token in this parameter and confirming its value in the redirect to mitigate against cross-site request forgery (CSRF).

除了提供 participant_id 之外,您还应该提供一个防伪令牌来帮助对抗 CSRF。