【问题标题】:How to fix 'function' object has no attribute 'create_authorization_url' when using Authlib?使用Authlib时如何修复'function'对象没有属性'create_authorization_url'?
【发布时间】:2019-08-09 10:08:13
【问题描述】:

我正在编写一个连接到 Budget Insight https://www.budget-insight.com/ 的 API,以从最终用户那里获取财务数据。

Budget Insight 在 Web 视图上使用 Oauth2 身份验证,要求用户输入其凭据以生成代码,然后用于交换令牌。

我已经为我的项目安装了 authlib 及其依赖项,并尝试了不同的方法来完成这项工作

第一种方式

budgea = OAuth2Session(
    client_id="37246252",
    client_secret=os.getenv("BUDGEA_CLIENT_SECRET"),
    redirect_uri="http://127.0.0.1:5000/budgea_callback",
)

第二种方式

budgea = oauth2.register(
    "budgea",
    client_id="37246252",
    client_secret=os.getenv("BUDGEA_CLIENT_SECRET"),
    access_token_url="https://ynab-fr-sandbox.biapi.pro/2.0/auth/token/access",
    authorize_url="https://ynab-fr-sandbox.biapi.pro/2.0/auth/webview/connect/select?client_id=37246252&redirect_uri=http:%2F%2F127.0.0.1:5000%2Fbudgea_callback",
    api_base_url="https://ynab-fr-sandbox.biapi.pro/2.0/",
    client_kwargs=None,
)

紧随其后

@app.route("/budgea")
def budgea():
    authorize_url = "https://ynab-fr-sandbox.biapi.pro/2.0/auth/webview/connect/select?client_id=37246252&redirect_uri=http:%2F%2F127.0.0.1:5000%2Fbudgea_callback"
    uri, state = budgea.create_authorization_url(authorize_url)
    return uri

当我访问 /budgea 路由时,两种方式都返回 AttributeError: 'function' object has no attribute 'create_authorization_url'。

【问题讨论】:

    标签: python-3.x flask oauth-2.0 authlib


    【解决方案1】:

    您使用的 Authlib 版本是什么?请使用最新版本的 Authlib。

    1. 然后尝试create_authorization_urlOAuth2Session 方式
    2. 第二种方式是Flask客户端方式,应该使用

      return client.authorize_redirect(callback_uri)
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-08
      • 2019-10-12
      • 2018-03-09
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2023-03-21
      相关资源
      最近更新 更多