puiterwijk / flask-oidc

OpenID Connect support for Flask
BSD 2-Clause "Simplified" License
154 stars 217 forks source link

Unable to get token info with WSO2 IS #120

Open amelroua opened 3 years ago

amelroua commented 3 years ago

I am trying to setup WSO2 IS with a simple flask api. I am trying to use https://gist.github.com/thomasdarimont/145dc9aa857b831ff2eff221b79d179a, however, I get always token invalid with unable to get token info error.

Code: app.py

` import json import logging from flask import Flask, g from flask_oidc import OpenIDConnect import requests

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_USER_INFO_ENABLED': True, 'OIDC_OPENID_REALM': 'manager', 'OIDC_SCOPES': ['openid', 'email', 'profile'], 'OIDC_CALLBACK_ROUTE': '/oidc/callback', 'OIDC_INTROSPECTION_AUTH_METHOD': 'client_secret_post', 'OIDC_TOKEN_TYPE_HINT': 'access_token', 'OIDC_CLOCK_SKEW': 560 #iat must be > time.time() - OIDC_CLOCK_SKEW })

oidc = OpenIDConnect(app) @app.route('/') def hello_world(): if oidc.user_loggedin: return ('Hello, %s, See private ' 'Log out') % \ oidc.user_getfield('preferred_username') else: return 'Welcome anonymous, Log in'

@app.route('/api', methods=['POST']) @oidc.accept_token(require_token=True) def hello_api(): """OAuth 2.0 protected API endpoint accessible via AccessToken""" return json.dumps({'hello': 'Welcome %s' % g.oidc_token_info['sub']})

@app.route('/logout') def logout(): """Performs local logout by removing the session cookie.""" oidc.logout() return 'Hi, you have been logged out! Return'

if name == 'main': app.run(debug=True, host='0.0.0.0')`

client_secret.json:

`{ "web": { "issuer": "https://localhost:9443/oauth2/token", "auth_uri": "https://localhost:9443/oauth2/authorize", "client_id": "xxxx", "client_secret": "xxxx", "redirect_uris": [ "http://localhost:5000/oidc/callback" ], "userinfo_uri": "https://localhost:9443/oauth2/userinfo?schema=openid", "token_uri": "https://localhost:9443/oauth2/token", "token_introspection_uri": "https://locahost:9443/oauth2/introspect",

   }

} `

I'm trying to access http://localhost:5000/api with authorization header bearer access token:

The flask error shows ERROR:flask_oidc:ERROR: Unable to get token info ERROR:flask_oidc:Expecting value: line 1 column 1 (char 0)