I am using flask to build app and keycloak for authorization.
from flask import Flask, session, request
from keycloak import KeycloakOpenID
app = Flask(__name__)
app.secret_key = 's_k'
keycloak_open_id = KeycloakOpenID(server_url="http://localhost:8080/auth/",
client_id="Centrum",
realm_name="myrealm",
client_secret_key="c_k")
def login_required(func):
@wraps(func)
def decorated(*args, **kwargs):
// validate token
return func('2', *args, **kwargs)
return decorated
@app.route('/login')
def login():
url = keycloak_open_id.auth_url('http://localhost:5555/auth')
# how to get a token and assign it to session['token']?
return redirect(url, code=302)
@app.route('/home')
@login_required
def home():
return 'Base URL!'
When I am logged in and can go to /home, but without token the application always needs to go through keycloak's method. Is there any other posibility to get token other than making own login form and pass login and password into keycloak_open_id.token(login, password) method?