Skip to content

Commit

Permalink
OIDC expiring fix (armadaproject#3506)
Browse files Browse the repository at this point in the history
* Checking for expired user

* Change to signing redirect
  • Loading branch information
mijovicmia authored Apr 8, 2024
1 parent a23af3d commit 1fc5822
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/lookout/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function AuthWrapper({ children, userManager, isAuthenticated }: AuthWrapperProp
const handleAuthentication = async () => {
try {
const user = await userManager.getUser()
if (!user) {
if (!user || user.expired) {
await userManager.signinRedirect()
}
} catch (error) {
Expand Down
20 changes: 18 additions & 2 deletions internal/lookout/ui/src/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@ export function useUserManager(): UserManager | undefined {

export async function getAccessToken(userManager: UserManager): Promise<string> {
const user = await userManager.getUser()
if (user !== null && !user.expired) return user.access_token
return (await userManager.signinPopup()).access_token

if (user !== null && !user.expired) {
return user.access_token
}

try {
await userManager.signinRedirect()
} catch (err) {
console.error("Error during sign-in redirect:", err)
throw err
}

const redirectedUser = await userManager.getUser()
if (redirectedUser !== null) {
return redirectedUser.access_token
}

throw new Error("Failed to obtain access token after sign-in redirect")
}

export function getAuthorizationHeaders(accessToken: string): Headers {
Expand Down

0 comments on commit 1fc5822

Please sign in to comment.