From 2809b95c170792e57151088a48649a4c06b65ffe Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Wed, 8 May 2024 19:35:06 +0200 Subject: [PATCH] Made sure that `CONNECTUM_OAUTH_CLIENT_{ID,SECRET}` is stripped --- data/external/scrapers/tumonline.py | 6 +++++- server/main-api/src/calendar/fetch/connectum.rs | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/data/external/scrapers/tumonline.py b/data/external/scrapers/tumonline.py index 9f26611e9..d626b5208 100644 --- a/data/external/scrapers/tumonline.py +++ b/data/external/scrapers/tumonline.py @@ -29,7 +29,11 @@ def _generate_oauth_headers() -> dict[typing.Literal["Authorization"], str]: oauth_client = BackendApplicationClient(client_id=oauth_client_id) oauth_session = OAuth2Session(client=oauth_client) - token = oauth_session.fetch_token(token_url=token_url, client_id=oauth_client_id, client_secret=oauth_client_secret) + token = oauth_session.fetch_token( + token_url=token_url, + client_id=oauth_client_id.strip(), + client_secret=oauth_client_secret.strip(), + ) assert token is not None return {"Authorization": f"Bearer {token['access_token']}"} diff --git a/server/main-api/src/calendar/fetch/connectum.rs b/server/main-api/src/calendar/fetch/connectum.rs index e550b5fad..3c075e76f 100644 --- a/server/main-api/src/calendar/fetch/connectum.rs +++ b/server/main-api/src/calendar/fetch/connectum.rs @@ -111,15 +111,17 @@ impl APIRequestor { } async fn fetch_oauth_token(&self) -> Result { let client_id = env::var("CONNECTUM_OAUTH_CLIENT_ID") - .map_err(|e| { - error!("CONNECTUM_OAUTH_CLIENT_ID needs to be set: {e:?}"); - io::Error::other("please configure the environment variable CONNECTUM_OAUTH_CLIENT_ID to use this endpoint") - })?; + .map_err(|e| { + error!("CONNECTUM_OAUTH_CLIENT_ID needs to be set: {e:?}"); + io::Error::other("please configure the environment variable CONNECTUM_OAUTH_CLIENT_ID to use this endpoint") + })? + .trim().into(); let client_secret = env::var("CONNECTUM_OAUTH_CLIENT_SECRET") .map_err(|e| { error!("CONNECTUM_OAUTH_CLIENT_SECRET needs to be set: {e:?}"); io::Error::other("please configure the environment variable CONNECTUM_OAUTH_CLIENT_SECRET to use this endpoint") - })?; + })? + .trim().into(); // for urls see https://campus.tum.de/tumonline/co/public/sec/auth/realms/CAMPUSonline/.well-known/openid-configuration let auth_url = Url::parse("https://campus.tum.de/tumonline/co/public/sec/auth/realms/CAMPUSonline/protocol/openid-connect/auth")?;