Last active
July 29, 2020 15:53
-
-
Save Louuu/2ae2215e237549663072a3378b552f4a to your computer and use it in GitHub Desktop.
keycloak flask app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, g | |
from flask_oidc import OpenIDConnect | |
app = Flask(__name__) | |
app.config.update({ | |
'SECRET_KEY': 'supercalifragilisticexpialidocious', | |
'TESTING': True, | |
'DEBUG': True, | |
'OIDC_CLIENT_SECRETS': 'client_secrets.json', | |
'OIDC_COOKIE_SECURE': False, | |
'OIDC_REQUIRE_VERIFIED_EMAIL': False, | |
'OIDC_USER_INFO_ENABLED': True, | |
'OIDC_OPENID_REALM': 'louisland', | |
'OIDC_INTROSPECTION_AUTH_METHOD': 'client_secret_post' | |
}) | |
oidc = OpenIDConnect(app) | |
@app.route('/') | |
def index(): | |
if oidc.user_loggedin: | |
return 'Welcome %s' % oidc.user_getfield('email') | |
else: | |
return 'Not logged in' | |
@app.route('/login') | |
@oidc.require_login | |
def login(): | |
return 'Welcome %s' % oidc.user_getfield('email') | |
if __name__ == "__main__": | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"web": { | |
"issuer": "http://localhost:8080/auth/realms/louisland", | |
"auth_uri": "http://localhost:8080/auth/realms/louisland/protocol/openid-connect/auth", | |
"client_id": "flask-demo", | |
"client_secret": "c92f8d00-a0cc-4b2b-8425-28f473e74769", | |
"redirect_uris": [ | |
"http://localhost:5000/*" | |
], | |
"userinfo_uri": "http://localhost:8080/auth/realms/louisland/protocol/openid-connect/userinfo", | |
"token_uri": "http://localhost:8080/auth/realms/louisland/protocol/openid-connect/token", | |
"token_introspection_uri": "http://localhost:8080/auth/realms/louisland/protocol/openid-connect/token/introspect" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment