Commit 545e114
authored
console: OIDC login in console (#35440)
Remove these sections if your commit already has a good description!
### Motivation
This PR adds OIDC authentication for self managed console. [Linear
issue:
CNS-25](7127d37#diff-af9c8f7e6f839e4e44fed50cfbe560c70bd845b062b946eaec012d825721f3c6)
### Description
For the console to handle oidc authentication, here are the changes in
this PR:
- Added `oidc-client-ts` and `react-oidc-context` libraries to the
console
- Created an OIDC library wrapper for oidc libary to create a shared
`User Manager` that caches ID token and exports the id token to be
consumed by api client
- Tests that mock the oidc token and functions
- Added "Oidc" to AppConfig so that oidc auth mode can be parsed from
app-config.json
- Created the `OidcProviderWrapper.tsx` to initialize OIDC UserManager
and wrap the children in AuthProvider when authmode === oidc
- In apiClient.ts, when `authMode === oidc`, oidc middleware will add a
`Authorization: Bearer <idToken>` if token exists. If no token, no
header is sent -- session cookie is used implicitly. If a session
expires, 401 redirect would handle expired sessions
- In the websocket, `getWsAuthConfig` returns the ID token if available,
`null` otherwise
- Allow "Oidc" in auth.ts for password auth to work alongside OIDC
- In the Login Box, the password auth option would also render along
with "Use Single Sign on" link
**Auth Flow:**
```
User clicks "Use single sign-on"
│
▼
┌──────────────────────────────────┐
│ Login.tsx: SsoLoginLink │
│ auth.signinRedirect() │
└──────────────┬───────────────────┘
│
│ oidc-client-ts:
│ 1. Generate code_verifier + code_challenge
│ 2. Store in sessionStorage
│ 3. Redirect browser
│
▼
┌──────────────────────────────────┐
│ Auth0 /authorize │
│ ?response_type=code │
│ &client_id=jM1iDueUB3ucXyUgPbsZ│
│ &redirect_uri=.../auth/callback │
│ &scope=openid profile email │
│ &code_challenge=<hash> │
│ &code_challenge_method=S256 │
│ &state=<random> │
└──────────────┬───────────────────┘
│
▼
┌──────────────────────────────────┐
│ Auth0 login page │
│ User enters credentials / MFA │
└──────────────┬───────────────────┘
│
│ Auth0 redirects:
│ /auth/callback?code=<authz_code>&state=<random>
│
▼
┌──────────────────────────────────┐
│ UnauthenticatedRoutes.tsx │
│ OidcAuthGuard │
│ │
│ hasAuthParams() → true │
│ (code + state in URL) │
│ → render <LoadingScreen /> │
└──────────────┬───────────────────┘
│
│ AuthProvider (react-oidc-context)
│ detects callback params, calls
│ userManager.signinRedirectCallback()
│
▼
┌──────────────────────────────────┐
│ oidc-client-ts token exchange │
│ │
│ POST Auth0 /oauth/token │
│ { │
│ grant_type: authorization_code│
│ code: <authz_code> │
│ code_verifier: <from storage> │
│ redirect_uri: .../auth/callback│
│ client_id: jM1iDueUB3ucXyUgPb│
│ } │
│ │
│ Auth0 responds: │
│ { id_token, access_token } │
└──────────────┬───────────────────┘
│
│ oidc-client-ts stores user
│ in sessionStorage, fires
│ userLoaded event
│
▼
┌──────────────────────────────────┐
│ oidc.ts │
│ userLoaded callback: │
│ cachedIdToken = user.id_token │
└──────────────┬───────────────────┘
│
│ auth.isLoading → false
│ auth.isAuthenticated → true
│ OidcAuthGuard renders children
│
▼
┌──────────────────────────────────┐
│ Authenticated Routes │
│ │
│ Every API call: │
│ apiClient.ts oidcAuthMiddleware │
│ → getOidcIdToken() returns token│
│ → Authorization: Bearer <token> │
└──────────────────────────────────┘
```
### Reviewing Tips
- Would recommend reviewing it by commit. First commit sets up the oidc
setup in the app. Second commit focuses on making it work with password
auth
### Verification
https://github.com/user-attachments/assets/49ca70b5-3e0d-48d6-88db-ca4ab20eb2631 parent b09c311 commit 545e114
File tree
15 files changed
+583
-107
lines changed- console
- src
- api
- materialize
- components
- config
- external-library-wrappers
- __mocks__
- layouts
- platform
- auth
15 files changed
+583
-107
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
165 | 170 | | |
166 | 171 | | |
167 | 172 | | |
| |||
179 | 184 | | |
180 | 185 | | |
181 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
182 | 202 | | |
183 | 203 | | |
184 | 204 | | |
185 | 205 | | |
186 | 206 | | |
187 | 207 | | |
188 | 208 | | |
189 | | - | |
190 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
191 | 229 | | |
192 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
193 | 240 | | |
194 | 241 | | |
195 | 242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
81 | | - | |
| 83 | + | |
| 84 | + | |
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
0 commit comments