core/proxy: handle missing session for user info endpoint (#4769)

This commit is contained in:
Caleb Doxsey 2024-01-08 07:03:49 -07:00 committed by GitHub
parent b3cb21e13c
commit 2dbcf32cc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 55 deletions

View file

@ -67,18 +67,16 @@ func (p *Proxy) getUserInfoData(r *http.Request) (handlers.UserInfoData, error)
} }
ss, err := p.getSessionState(r) ss, err := p.getSessionState(r)
if err != nil { if err == nil {
return handlers.UserInfoData{}, err data.Session, data.IsImpersonated, err = p.getSession(r.Context(), ss.ID)
} if err != nil {
data.Session = &session.Session{Id: ss.ID}
}
data.Session, data.IsImpersonated, err = p.getSession(r.Context(), ss.ID) data.User, err = p.getUser(r.Context(), data.Session.GetUserId())
if err != nil { if err != nil {
data.Session = &session.Session{Id: ss.ID} data.User = &user.User{Id: data.Session.GetUserId()}
} }
data.User, err = p.getUser(r.Context(), data.Session.GetUserId())
if err != nil {
data.User = &user.User{Id: data.Session.GetUserId()}
} }
data.WebAuthnCreationOptions, data.WebAuthnRequestOptions, _ = p.webauthn.GetOptions(r) data.WebAuthnCreationOptions, data.WebAuthnRequestOptions, _ = p.webauthn.GetOptions(r)

View file

@ -1,3 +1,5 @@
import Alert from "@mui/material/Alert";
import AlertTitle from "@mui/material/AlertTitle";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import Table from "@mui/material/Table"; import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody"; import TableBody from "@mui/material/TableBody";
@ -20,50 +22,66 @@ export const SessionDetails: FC<SessionDetailsProps> = ({
profile, profile,
}) => { }) => {
return ( return (
<Section title="User Details"> <>
<Stack spacing={3}> {session?.id ? (
<TableContainer> <Section title="User Details">
<Table size="small"> <Stack spacing={3}>
<TableBody> <TableContainer>
<TableRow> <Table size="small">
<TableCell width={"18%"} variant="head"> <TableBody>
Session ID <TableRow>
</TableCell> <TableCell width={"18%"} variant="head">
<TableCell align="left"> Session ID
<IDField value={session?.id} /> </TableCell>
</TableCell> <TableCell align="left">
</TableRow> <IDField value={session?.id} />
<TableRow> </TableCell>
<TableCell variant="head">User ID</TableCell> </TableRow>
<TableCell align="left"> <TableRow>
<IDField <TableCell variant="head">User ID</TableCell>
value={session?.userId || `${profile?.claims?.sub}`} <TableCell align="left">
/> <IDField
</TableCell> value={
</TableRow> session?.userId || `${profile?.claims?.sub || ""}`
<TableRow> }
<TableCell variant="head">Expires At</TableCell> />
<TableCell align="left">{session?.expiresAt || ""}</TableCell> </TableCell>
</TableRow> </TableRow>
{Object.entries(session?.claims || {}).map(([key, values]) => ( <TableRow>
<ClaimRow <TableCell variant="head">Expires At</TableCell>
key={`session/${key}`} <TableCell align="left">
claimKey={key} {session?.expiresAt || ""}
claimValue={values} </TableCell>
/> </TableRow>
))} {Object.entries(session?.claims || {}).map(
{Object.entries(profile?.claims || {}).map(([key, value]) => ( ([key, values]) => (
<ClaimRow <ClaimRow
key={`profile/${key}`} key={`session/${key}`}
claimKey={key} claimKey={key}
claimValue={value} claimValue={values}
/> />
))} )
</TableBody> )}
</Table> {Object.entries(profile?.claims || {}).map(([key, value]) => (
</TableContainer> <ClaimRow
</Stack> key={`profile/${key}`}
</Section> claimKey={key}
claimValue={value}
/>
))}
</TableBody>
</Table>
</TableContainer>
</Stack>
</Section>
) : (
<Alert severity="warning">
<AlertTitle>User Details Not Available</AlertTitle>
Have you signed in yet? <br />
<a href="/">{location.origin}</a>.
</Alert>
)}
</>
); );
}; };
export default SessionDetails; export default SessionDetails;