Skip to content

Commit 123b6cb

Browse files
committedMar 28, 2024
update auth bits from enterprise
1 parent eab9e37 commit 123b6cb

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed
 

‎packages/web-console/src/modules/OAuth2/views/login.tsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export const Login = ({
238238
}, 5000)
239239
}, [errorMessage])
240240

241-
return (
241+
return settings["acl.basic.auth.realm.enabled"] ? null : (
242242
<div>
243243
<Header>
244244
<a href={"https://questdb.io"}>
@@ -259,19 +259,19 @@ export const Login = ({
259259
*/}
260260
<Title>Please Sign In</Title>
261261
{settings["acl.oidc.enabled"] && (
262-
<SSOCard>
263-
<StyledButton
264-
skin="secondary"
265-
prefixIcon={<User size="18px" />}
266-
onClick={() => onOAuthLogin()}
267-
>
268-
Continue with SSO
269-
</StyledButton>
270-
<Line>
271-
<LineText color="gray2">or</LineText>
272-
</Line>
273-
</SSOCard>
274-
)}
262+
<SSOCard>
263+
<StyledButton
264+
skin="secondary"
265+
prefixIcon={<User size="18px" />}
266+
onClick={() => onOAuthLogin()}
267+
>
268+
Continue with SSO
269+
</StyledButton>
270+
<Line>
271+
<LineText color="gray2">or</LineText>
272+
</Line>
273+
</SSOCard>
274+
)}
275275
<Card hasError={errorMessage}>
276276
<Form<FormValues>
277277
name="login"

‎packages/web-console/src/providers/AuthProvider.tsx

+29-15
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
6060
)
6161
const [loggedOut, setLoggedOut] = useState(false)
6262

63-
const basicAuthEnabled = settings["acl.basic.auth.realm.enabled"]
64-
6563
const setAuthToken = (tokenResponse: AuthPayload) => {
6664
if (tokenResponse.access_token) {
6765
setValue(
@@ -187,25 +185,41 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
187185
)
188186
// Stop loading and display the login state
189187
} else {
190-
checkIfBasicAuth()
188+
uiAuthLogin()
191189
}
192190
}
193-
} else if (basicAuthEnabled) {
194-
// run a simple query to force basic auth by browser
195-
await fetch(`${window.location.origin}/exec?query=select 42`)
191+
} else if (
192+
// We need to explicitly check for the Boolean value, because the settings response might not come up from the API
193+
// yet, and therefore be still undefined by default
194+
typeof settings["acl.basic.auth.realm.enabled"] !== "undefined"
195+
) {
196+
if (settings["acl.basic.auth.realm.enabled"]) {
197+
await basicAuthLogin()
198+
} else {
199+
// Subscribe for any subsequent REST 401 responses (incorrect token, etc)
200+
eventBus.subscribe(EventType.MSG_CONNECTION_UNAUTHORIZED, () => {
201+
logout()
202+
})
203+
204+
//username + pwd via login page
205+
uiAuthLogin()
206+
}
207+
}
208+
}
209+
210+
const basicAuthLogin = async () => {
211+
// run a simple query to force basic auth by browser
212+
const response = await fetch(
213+
`${window.location.origin}/exec?query=select 42`,
214+
)
215+
if (response.status === 200) {
196216
setReady(true)
197217
} else {
198-
// Subscribe for any subsequent REST 401 responses (incorrect token, etc)
199-
eventBus.subscribe(EventType.MSG_CONNECTION_UNAUTHORIZED, () => {
200-
logout()
201-
})
202-
203-
//username + pwd via login page
204-
checkIfBasicAuth()
218+
await basicAuthLogin()
205219
}
206220
}
207221

208-
const checkIfBasicAuth = () => {
222+
const uiAuthLogin = () => {
209223
// Check if user is authenticated already with basic auth
210224
const token = getValue(StoreKey.REST_TOKEN)
211225
if (token) {
@@ -289,7 +303,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
289303
<Error
290304
errorMessage={errorMessage}
291305
onLogout={logout}
292-
basicAuthEnabled={basicAuthEnabled}
306+
basicAuthEnabled={settings["acl.basic.auth.realm.enabled"] ?? false}
293307
/>
294308
)
295309
} else if (loading) {

‎packages/web-console/src/store/Console/reducers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const defaultSettings: ConsoleSettingsShape = {
5252
"acl.oidc.authorization.endpoint": "",
5353
"acl.oidc.token.endpoint": "",
5454
"acl.oidc.pkce.required": true,
55-
"acl.basic.auth.realm.enabled": false,
55+
"acl.basic.auth.realm.enabled": undefined,
5656
}
5757

5858
const _console = (

‎packages/web-console/src/store/Console/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export type ConsoleSettings = Readonly<{
4949
"acl.oidc.authorization.endpoint": string
5050
"acl.oidc.token.endpoint": string
5151
"acl.oidc.pkce.required": boolean
52-
"acl.basic.auth.realm.enabled": boolean
52+
"acl.basic.auth.realm.enabled"?: boolean
5353
}>
5454

5555
export type ConsoleSettingsShape = Readonly<ConsoleSettings>

0 commit comments

Comments
 (0)
Failed to load comments.