access token verification on API endpoint
This commit is contained in:
parent
e2db6cf56b
commit
c716960e97
10
app.py
10
app.py
@ -1,10 +1,12 @@
|
|||||||
import requests
|
import requests
|
||||||
|
import jwt
|
||||||
|
|
||||||
from authlib.integrations.base_client import OAuthError
|
from authlib.integrations.base_client import OAuthError
|
||||||
from authlib.integrations.flask_client import OAuth
|
from authlib.integrations.flask_client import OAuth
|
||||||
|
|
||||||
from flask import Flask, request, redirect, session, render_template, url_for, make_response
|
from flask import Flask, request, redirect, session, render_template, url_for, make_response
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SECRET_KEY'] = 'onelogindemopytoolkit'
|
app.config['SECRET_KEY'] = 'onelogindemopytoolkit'
|
||||||
|
|
||||||
@ -33,7 +35,11 @@ def api():
|
|||||||
# it is not OK to use ID token to check API authorization on server side
|
# it is not OK to use ID token to check API authorization on server side
|
||||||
if 'accessToken' in request.args:
|
if 'accessToken' in request.args:
|
||||||
access_token = request.args['accessToken']
|
access_token = request.args['accessToken']
|
||||||
#claims = oidcclient.validate_jwt(access_token)
|
jwks_uri = f"{issuer}/protocol/openid-connect/certs"
|
||||||
|
jwks_client = jwt.PyJWKClient(jwks_uri)
|
||||||
|
key = jwks_client.get_signing_key_from_jwt(access_token)
|
||||||
|
data = jwt.decode(access_token, key.key, algorithms=["RS256"], audience='client-oidc', options={'verify_signature': True, 'verify_aud': True})
|
||||||
|
print(data)
|
||||||
not_auth_warn = False
|
not_auth_warn = False
|
||||||
# TODO verify token and check role
|
# TODO verify token and check role
|
||||||
return render_template(
|
return render_template(
|
||||||
@ -88,7 +94,9 @@ def index():
|
|||||||
response.set_cookie('accessToken', '', expires=0)
|
response.set_cookie('accessToken', '', expires=0)
|
||||||
response.set_cookie('refreshToken', '', expires=0)
|
response.set_cookie('refreshToken', '', expires=0)
|
||||||
response.set_cookie('idToken', '', expires=0)
|
response.set_cookie('idToken', '', expires=0)
|
||||||
|
if 'name' in session:
|
||||||
del session['name']
|
del session['name']
|
||||||
|
if 'email' in session:
|
||||||
del session['email']
|
del session['email']
|
||||||
return response
|
return response
|
||||||
elif 'error' in request.args:
|
elif 'error' in request.args:
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
authlib
|
authlib
|
||||||
flask
|
flask
|
||||||
|
PyJWT
|
||||||
|
Loading…
Reference in New Issue
Block a user