我有一个 flask 驱动的应用程序,我正在尝试为此应用程序启用 OIDC SSO。我选择 wso2 作为身份服务器。我已经创建了一个回调 URL 并在身份服务器和 flask 应用程序中添加了必要的东西,如下所示。该应用程序能够通过凭据日志记录页面,之后,我收到 SSL 证书验证错误。
我的尝试:
- 我尝试使用自签名证书,但
app.run(ssl_context='adhoc')
没有用。
代码片段:
from flask import Flask, g
from flask_oidc import OpenIDConnect
# import ssl
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)
app.config.update({
'SECRET_KEY': 'SomethingNotEntirelySecret',
'TESTING': True,
'DEBUG': True,
'OIDC_CLIENT_SECRETS': 'client_secrets.json',
'OIDC_ID_TOKEN_COOKIE_SECURE': False,
'OIDC_REQUIRE_VERIFIED_EMAIL': False,
})
oidc = OpenIDConnect(app)
@app.route('/private')
@oidc.require_login
def hello_me():
# import pdb;pdb.set_trace()
info = oidc.user_getinfo(['email', 'openid_id'])
return ('Hello, %s (%s)! <a href="/">Return</a>' %
(info.get('email'), info.get('openid_id')))
if __name__ == '__main__':
# app.run(host='sanudev', debug=True)
# app.run(debug=True)
# app.run(ssl_context='adhoc')
app.run(ssl_context=('cert.pem', 'key.pem'))
# app.run(ssl_context=('cert.pem', 'key.pem'))
客户信息:
{
"web": {
"auth_uri": "https://localhost:9443/oauth2/authorize",
"client_id": "hXCcX_N75aIygBIY7IwnWRtRpGwa",
"client_secret": "8uMLQ92Pm8_dPEjmGSoGF7Y6fn8a",
"redirect_uris": [
"https://sanudev:5000/oidc_callback"
],
"userinfo_uri": "https://localhost:9443/oauth2/userinfo",
"token_uri": "https://localhost:9443/oauth2/token",
"token_introspection_uri": "https://localhost:9443/oauth2/introspect"
}
}
应用信息:
- python 3.8
- flask 1.1.2
最佳答案
嗨,回答我自己的问题只是为了有效地接触社区,在这里我可以表达我卡在哪里以及修复背后的所有故事。
TLDR:
出现 SSL 问题是因为在 OIDC 流程中,wso2 服务器必须仅通过 SSL 隧道通信或传输安全身份验证 token 。这是出于安全目的需要保留的强制性标准。 是的,carbon 服务器有 SSL 证书(自签名证书)以通过 SSL 隧道客户端进行安全 token 传输,也必须至少进行自签名证书配置。
因为我使用的是 flask-oidc 库,所以有一个允许的规定,请引用这里的配置。
{
"web": {
"auth_uri": "https://localhost:9443/oauth2/authorize",
"client_id": "someid",
"client_secret": "somesecret",
"redirect_uris": [
"https://localhost:5000/oidc_callback"
],
"userinfo_uri": "http://localhost:9763/oauth2/userinfo",
"token_uri": "http://localhost:9763/oauth2/token",
"token_introspection_uri": "http://localhost:9763/oauth2/introspect",
"issuer": "https://localhost:9443/oauth2/token" # This can solve your issue
}
}
为了快速开发,您可以通过在 Flask 应用程序运行设置中添加临时配置来启用 HTTPS 中的安全连接。
if __name__ == '__main__':
# app.run(ssl_context=('cert.pem', 'key.pem')) # for self signed cert
app.run(debug=True, ssl_context='adhoc') # Adhoc way of making https
关于ssl - Flask SSL 证书中的 OIDC SSO 验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64591016/