diff options
author | Frédéric Mangano-Tarumi <fmang@mg0.fr> | 2020-06-04 22:00:20 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2021-02-20 17:24:30 +0100 |
commit | 3b347d3989592293661a47a5bac7645afb8d61d6 (patch) | |
tree | ea3f86cadb041c46580e3c9ef7a3a2bb6a70a056 /aurweb/routers/sso.py | |
parent | b1300117ac6fc0f5e9cf1048576db8fb97470bcc (diff) | |
download | aur-3b347d3989592293661a47a5bac7645afb8d61d6.tar.gz aur-3b347d3989592293661a47a5bac7645afb8d61d6.tar.xz |
Crude OpenID Connect client using Authlib
Developers can go to /sso/login to get redirected to the SSO. On
successful login, the ID token is displayed.
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'aurweb/routers/sso.py')
-rw-r--r-- | aurweb/routers/sso.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/aurweb/routers/sso.py b/aurweb/routers/sso.py new file mode 100644 index 00000000..b16edffb --- /dev/null +++ b/aurweb/routers/sso.py @@ -0,0 +1,30 @@ +import fastapi + +from authlib.integrations.starlette_client import OAuth +from starlette.requests import Request + +import aurweb.config + +router = fastapi.APIRouter() + +oauth = OAuth() +oauth.register( + name="sso", + server_metadata_url=aurweb.config.get("sso", "openid_configuration"), + client_kwargs={"scope": "openid"}, + client_id=aurweb.config.get("sso", "client_id"), + client_secret=aurweb.config.get("sso", "client_secret"), +) + + +@router.get("/sso/login") +async def login(request: Request): + redirect_uri = aurweb.config.get("options", "aur_location") + "/sso/authenticate" + return await oauth.sso.authorize_redirect(request, redirect_uri, prompt="login") + + +@router.get("/sso/authenticate") +async def authenticate(request: Request): + token = await oauth.sso.authorize_access_token(request) + user = await oauth.sso.parse_id_token(request, token) + return dict(user) |