【发布时间】:2019-12-07 02:48:09
【问题描述】:
我有在 docker (192.168.99.100:8080) 中运行的 keycloak 服务器和在本地运行的 python flask-oidc flask 应用程序 (localhost:5000) 我即使在获取 access_token 后也无法访问受保护的 Rest Api。有没有人试过这个代码。如果是这样,请帮助我解决这个问题。谢谢你
this is my keycloak client using docker jboss/keycloak image
this is my newuser under the new realm
下面是我的烧瓶应用程序
app.py
from flask import Flask, g
from flask_oidc import OpenIDConnect
import requests
secret_key = os.urandom(24).hex()
print(secret_key)
logging.basicConfig(level=logging.DEBUG)
app = Flask(__name__)
app.config["OIDC_CLIENT_SECRETS"]="client_secrets.json"
app.config["OIDC_COOKIE_SECURE"]=False
app.config["OIDC_SCOPES"]=["openid","email","profile"]
app.config["SECRET_KEY"]=secret_key
app.config["TESTING"]=True
app.config["DEBUG"] = True
app.config["OIDC_ID_TOKEN_COOKIE_SECURE"]=False
app.config["OIDC_REQUIRED_VERIFIED_EMAIL"]=False
app.config["OIDC_INTROSPECTION_AUTH_METHOD"]='client_secret_post'
app.config["OIDC_USER_INFO_ENABLED"]=True
oidc = OpenIDConnect(app)
@app.route('/')
def hello_world():
if oidc.user_loggedin:
return ('Hello, %s, <a href="/private">See private</a> '
'<a href="/logout">Log out</a>') % \
oidc.user_getfield('preferred_username')
else:
return 'Welcome anonymous, <a href="/private">Log in</a>'
client_secrets.json
{
"web": {
"issuer": "http://192.168.99.100:8080/auth/realms/kariga",
"auth_uri": "http://192.168.99.100:8080/auth/realms/kariga/protocol/openid-connect/auth",
"client_id": "flask-app",
"client_secret": "eb11741d-3cb5-4457-8ff5-0202c6d6b250",
"redirect_uris": [
"http://localhost:5000/"
],
"userinfo_uri": "http://192.168.99.100:8080/auth/realms/kariga/protocol/openid-connect/userinfo",
"token_uri": "http://192.168.99.100:8080/auth/realms/kariga/protocol/openid-connect/token",
"token_introspection_uri": "http://192.168.99.100:8080/auth/realms/kariga/protocol/openid-connect/token/introspect"
}
}
当我在网络浏览器中启动烧瓶应用程序时
我点击登录链接
接下来它会提示输入 用户详细信息(在我的新领域下创建的用户)
它需要几秒钟,然后将我重定向到错误页面
http://localhost:5000/oidc_callback?state=eyJjc3JmX3Rva2VuIjogIkZZbEpqb3ZHblZoUkhEbmJsdXhEVW
那说
httplib2.socks.HTTPError
httplib2.socks.HTTPError: (504, b'Gateway Timeout')
而且它还重定向到 /oidc_callback 没有在任何地方提及
任何帮助将不胜感激
【问题讨论】:
标签: python keycloak flask-oidc