繁体   English   中英

在本地更新(Python Flask)后恢复 Auth0 访问令牌授权

[英]Restore Auth0 access token authorization after update (Python Flask) on local

我希望将本地/开发 Auth0 功能恢复到我最近从 Python 2.7 更新到 Python 3 (v) 的 Flask 应用程序。 Auth0 authorize_access_token现在在我的本地开发服务器上失败,但仍然可以在部署的临时站点上运行。 我没有对此代码或 Auth0 我的设置进行任何更改。

错误信息:

  File "/Users/h/.local/share/virtualenvs/stf-hashhere/lib/python3.8/site-packages/authlib/integrations/base_client/base_app.py", line 126, in _retrieve_oauth2_access_token_params
    raise MismatchingStateError()
authlib.integrations.base_client.errors.MismatchingStateError: mismatching_state: CSRF Warning! State not equal in request and response.

代码:

def create_app(test_config=None):
# Factory to create and configure the app
app = Flask(
    __name__,
    static_folder='../www/static',
    static_url_path='/static',
    template_folder='../www/static/dist',
    instance_relative_config=True,
)

oauth = OAuth(app) 
app.secret_key = app.config['SESSION_KEY']
auth0_base = 'https://{}'.format(app.config['AUTH0_API_AUDIENCE'])
auth0 = oauth.register(
    'auth0',
    client_id=app.config['AUTH0_CLIENT_ID'],
    client_secret=app.config['AUTH0_CLIENT_SECRET'],
    api_base_url=auth0_base,
    access_token_url='{}/oauth/token'.format(auth0_base),
    authorize_url='{}/authorize'.format(auth0_base),
    client_kwargs={
        'scope': 'openid profile email',
    },
)

@app.route('/earlybird')
def login():
    return auth0.authorize_redirect(redirect_uri=app.config['AUTH0_CALLBACK_URL'])

@app.route('/auth/callback')
def callback_handling():
    auth0.authorize_access_token()
    return redirect('/profile')


{'framework': <authlib.integrations.flask_client.integration.FlaskIntegration object at 0x110be03a0>, 'name': 'auth0', 'client_id': '<client>', 'client_secret': 'secret', 'request_token_url': None, 'request_token_params': None, 'access_token_url': 'https://smalltradeflora.auth0.com/oauth/token', 'access_token_params': None, 'authorize_url': 'https://smalltradeflora.auth0.com/authorize', 'authorize_params': None, 'api_base_url': 'https://smalltradeflora.auth0.com', 'client_kwargs': {'scope': 'openid profile email'}, 'compliance_fix': None, 'client_auth_methods': None, '_fetch_token': None, '_update_token': None, '_user_agent': 'Authlib/0.15.2 (+https://authlib.org/)', '_server_metadata_url': None, 'server_metadata': {'refresh_token_url': None, 'refresh_token_params': None}, '_fetch_request_token': None, '_save_request_token': None}
  • http://flora.loc:5000/auth/callback是我的Allowed Callback URL以及我的app.config['AUTH0_CALLBACK_URL']

我努力了:

  • 验证配置变量
  • 添加一个SESSION_NAME然后app.config.SESSION_COOKIE_NAME尝试每个这个SO 线程
  • 使用url_for('callback_handling', _external=True)确保 alignment 带回调
  • 验证不需要将 AUTHO 参数输入为字节(在这些代码行中, u''转换是 2.7 中唯一可见的顶级更改)
  • http://127.0.0.1:5000运行(相同端口)

我注意到@lepture 在这个线程中也有注释

在 Authlib 0.9 中,state 的 session 密钥已更改。

但我还不明白这如何或是否适用于我需要的代码调整。

我最终完全重写了我的应用程序工厂,从下载的 Oauth 为 Python Web 应用程序示例迭代构建。 代码的工作版本和非工作版本之间的两个主要区别是:

  • 使用localhost:5000作为我的本地主机地址。 我映射flora.loc基础将不起作用。 笔记:
    • 我仍然不确定为什么映射的主机名在此处没有 function (记录引用的flora.loc按预期显示了flora.loc,但必须有一些关于我尚未捕获的分辨率的内容)
    • 与往常一样,确保您的预期地址也列在您的 auth0 应用仪表板中。
  • 观众参数现在需要一个前置的https://才能成功解析

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM