more oidc

This commit is contained in:
Daniel Tsvetkov 2021-05-09 01:13:57 +02:00
parent 0e869bd55a
commit 01d1ac23de
2 changed files with 27 additions and 6 deletions

View File

@ -1 +1,3 @@
ADMIN_PASSWORD = "password"
SSO_CLIENT_ID = '123456'
SSO_CLIENT_SECRET = 'secret'

View File

@ -5,6 +5,7 @@ from flask import send_from_directory, redirect, request, url_for
from oshipka.webapp import oshipka_bp
from config import MEDIA_DIR, APP_BASE_URL
from sensitive import SSO_CLIENT_ID, SSO_CLIENT_SECRET
# TODO: VULNZ - EVERYONE HAS ACCESS TO THIS
@ -18,15 +19,33 @@ SSO_BASE_URL = 'http://localhost:5008'
@oshipka_bp.route('/sso')
def sso():
callback_url = APP_BASE_URL + url_for('oshipka_bp.open_id_connect_code')
return redirect(SSO_BASE_URL + '/authenticate?callback={}'.format(urllib.parse.quote(callback_url)))
callback_url = APP_BASE_URL + url_for('oshipka_bp.oidc_code')
return redirect(SSO_BASE_URL + '/authenticate?callback={}&client_id={}'.format(
urllib.parse.quote(callback_url),
SSO_CLIENT_ID,
))
@oshipka_bp.route('/open_id_connect_code')
def open_id_connect_code():
@oshipka_bp.route('/oidc/code')
def oidc_code():
code = request.args.get('code')
# TODO : client_id and client_secret are passed in Authorization header
# https://connect2id.com/learn/openid-connect
response = requests.get(
SSO_BASE_URL + "/token",
data={'code': code},
SSO_BASE_URL + "/oidc/token",
params={
'code': code,
'client_id': SSO_CLIENT_ID,
'client_secret': SSO_CLIENT_SECRET,
},
)
if response.status_code == 200:
response_json = response.json()
access_token = response_json.get('access_token')
response = requests.get(
SSO_BASE_URL + "/endpoints/user",
headers={
'Authorization': "Bearer {}".format(access_token)
},
)
return 'got response for token: {}'.format(response.status_code)