Skip to content

Commit 1f1eeff

Browse files
chore: improve logs, oidc wording
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent dcce8e6 commit 1f1eeff

6 files changed

Lines changed: 44 additions & 14 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ tower-http = { version = "0.7", default-features = false, features = [
8282
"cors",
8383
"set-header",
8484
"timeout",
85+
"trace",
8586
] }
8687
ua-parser = "0.2"
8788
url = "2.5"

‎src/main.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ async fn main() -> Result<()> {
4242

4343
fn setup_logger(log_level: tracing::Level) -> Result<()> {
4444
// external crates should use WARN
45-
let filter = EnvFilter::from_default_env()
45+
let mut filter = EnvFilter::from_default_env()
4646
.add_directive(format!("{}={}", env!("CARGO_PKG_NAME"), log_level).parse()?)
4747
.add_directive(tracing::Level::WARN.into());
48+
if log_level == tracing::Level::DEBUG || log_level == tracing::Level::TRACE {
49+
filter = filter.add_directive(format!("tower_http::trace={log_level}").parse()?);
50+
}
4851

4952
tracing_subscriber::fmt().with_env_filter(filter).compact().init();
5053

‎src/web/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use tower_http::{
1919
cors::{Any, CorsLayer},
2020
set_header::SetResponseHeaderLayer,
2121
timeout::RequestBodyDeadlineLayer,
22+
trace::TraceLayer,
2223
};
2324

2425
use crate::app::{
@@ -150,6 +151,7 @@ pub fn router(app: Arc<Liwan>, queues: EventQueues) -> Result<(axum::Router<()>,
150151
.layer(RequestBodyDeadlineLayer::new(Duration::from_secs(30)))
151152
.layer(CompressionLayer::new())
152153
.layer(set_headers)
154+
.layer(TraceLayer::new_for_http())
153155
.with_state(RouterState {
154156
app: app.clone(),
155157
events: queues.events,

‎src/web/routes/external_auth.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@ async fn start(
224224
if app.onboarding.token().is_some() {
225225
http_bail!(StatusCode::NOT_FOUND, "external authentication is unavailable");
226226
}
227-
let start = app
228-
.external_auth
229-
.begin(query.return_to)
230-
.await
231-
.http_err("external authentication is unavailable", StatusCode::BAD_REQUEST)?;
227+
let start = match app.external_auth.begin(query.return_to).await {
228+
Ok(start) => start,
229+
Err(error) => {
230+
tracing::warn!(%error, "external authentication start failed");
231+
http_bail!(StatusCode::BAD_REQUEST, "external authentication is unavailable");
232+
}
233+
};
232234
let mut state_cookie = STATE_COOKIE.clone();
233235
state_cookie.set_secure(app.config.secure());
234236
state_cookie.set_value(start.state);
@@ -273,7 +275,7 @@ async fn callback(
273275
}
274276
},
275277
Err(error) => {
276-
tracing::debug!(%error, "external authentication callback failed");
278+
tracing::warn!(%error, "external authentication callback failed");
277279
(cookies, Redirect::to(CALLBACK_ERROR_PATH)).into_response()
278280
}
279281
};

‎web/src/components/settings/auth/index.tsx‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styles from "./authentication.module.css";
22

3-
import { useEffect, useState } from "react";
3+
import { useEffect, useRef, useState } from "react";
44
import { SiGoogle, SiOpenid } from "@icons-pack/react-simple-icons";
55
import { KeyRoundIcon } from "lucide-react";
66

@@ -105,7 +105,7 @@ const ProviderSettings = ({
105105
<SettingsSwitch
106106
name="allowUserCreation"
107107
label="Allow new users"
108-
description="Create an account after a user's first verified sign-in."
108+
description="Create an account when a user signs in successfully for the first time."
109109
checked={settings.allowUserCreation}
110110
onCheckedChange={(allowUserCreation) => update("allowUserCreation", allowUserCreation)}
111111
/>
@@ -135,7 +135,10 @@ const ProviderSettings = ({
135135
/>
136136
</SettingsField>
137137
)}
138-
<SettingsField label="Client ID" name="clientId">
138+
<SettingsField
139+
label={settings.provider === "microsoft" ? "Application (client) ID" : "Client ID"}
140+
name="clientId"
141+
>
139142
<input
140143
name="clientId"
141144
value={settings.clientId}
@@ -192,7 +195,7 @@ const ProviderSettings = ({
192195
)}
193196
{settings.provider === "microsoft" && (
194197
<SettingsField
195-
label="Tenant ID"
198+
label="Directory (tenant) ID"
196199
description="The directory ID for the Microsoft Entra tenant that can sign in."
197200
name="tenantId"
198201
>
@@ -214,6 +217,9 @@ export const AuthenticationSettingsPage = () => {
214217
const [savedSettings, setSavedSettings] = useState<ExternalAuthSettings>();
215218
const [error, setError] = useState<string>();
216219
const [clientSecret, setClientSecret] = useState("");
220+
const providerDrafts = useRef<
221+
Partial<Record<ExternalAuthProvider, { settings: ExternalAuthSettings; clientSecret: string }>>
222+
>({});
217223

218224
useEffect(() => {
219225
api["/api/dashboard/admin/auth"]
@@ -222,6 +228,7 @@ export const AuthenticationSettingsPage = () => {
222228
.then((settings) => {
223229
setSettings(settings);
224230
setSavedSettings(settings);
231+
providerDrafts.current[settings.provider] = { settings, clientSecret: "" };
225232
})
226233
.catch((error) => setError(errorMessage(error)));
227234
}, []);
@@ -232,6 +239,7 @@ export const AuthenticationSettingsPage = () => {
232239
const update = <K extends keyof ExternalAuthSettings>(key: K, value: ExternalAuthSettings[K]) =>
233240
setSettings({ ...settings, [key]: value });
234241
const selectProvider = (provider: ExternalAuthProvider | "internal") => {
242+
providerDrafts.current[settings.provider] = { settings, clientSecret };
235243
if (provider === "internal") {
236244
setSettings({ ...settings, enabled: false });
237245
return;
@@ -240,17 +248,25 @@ export const AuthenticationSettingsPage = () => {
240248
setSettings({ ...settings, enabled: true });
241249
return;
242250
}
243-
setClientSecret("");
251+
252+
const draft = providerDrafts.current[provider];
253+
if (draft) {
254+
setSettings({ ...draft.settings, enabled: true });
255+
setClientSecret(draft.clientSecret);
256+
return;
257+
}
258+
244259
setSettings({
245260
...settings,
246261
enabled: true,
247262
provider,
248-
displayName: provider === "oidc" ? "OpenID Connect" : settings.displayName,
263+
displayName: providers.find((item) => item.value === provider)?.label ?? settings.displayName,
249264
clientId: "",
250265
issuerUrl: null,
251266
allowedDomain: null,
252267
tenantId: null,
253268
});
269+
setClientSecret("");
254270
};
255271

256272
const save = () => {
@@ -281,6 +297,7 @@ export const AuthenticationSettingsPage = () => {
281297
setSettings(next);
282298
setSavedSettings(next);
283299
setClientSecret("");
300+
providerDrafts.current[next.provider] = { settings: next, clientSecret: "" };
284301
createToast("Authentication settings updated", "success");
285302
})
286303
.catch((error) => {
@@ -319,7 +336,11 @@ export const AuthenticationSettingsPage = () => {
319336
{settings.enabled && (
320337
<div className={styles.callbackSection}>
321338
<h2>Callback URL</h2>
322-
<p>Add this exact URL to the provider application's allowed redirect URLs.</p>
339+
<p>
340+
{settings.provider === "microsoft"
341+
? "In Microsoft Entra ID, select the Web platform and add this exact URL as a redirect URI."
342+
: "Add this exact URL to the provider application's allowed redirect URLs."}
343+
</p>
323344
<CopyableValue value={settings.callbackUrl} label="Callback URL" />
324345
</div>
325346
)}

0 commit comments

Comments
 (0)