verdan / flaskoidc

A wrapper of Flask with pre-configured OIDC support
Apache License 2.0
52 stars 35 forks source link

`json.loads(token)` decode error because token is JWT, not json #23

Open ross-nordstrom opened 2 years ago

ross-nordstrom commented 2 years ago

Hi, I'm trying to use your middleware in my Flask API, authenticating with Keycloak, but I'm getting an error on token = json.loads(token). It seems like it's skipping a "decode jwt" step.

Below is my api setup -- am I using this wrong?

import os

# Got a lookup error when trying the `CustomConfig` approach from README
os.environ['FLASK_DEBUG'] = 'True'
os.environ['FLASK_OIDC_PROVIDER_NAME'] = 'keycloak'
os.environ['FLASK_OIDC_CLIENT_ID'] = 'api'
os.environ['FLASK_OIDC_CLIENT_SECRET'] = os.environ['API_CLIENT_SECRET']
os.environ['FLASK_OIDC_CONFIG_URL'] = 'http://keycloak:8080/auth/realms/global/.well-known/openid-configuration'
os.environ['FLASK_OIDC_USER_ID_FIELD'] = 'preferred_username'

from flask import g
from flaskoidc import FlaskOIDC

app = FlaskOIDC(__name__)

@app.route("/hello")
def hello():
    return g.oidc_token_info