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)
if err != nil {
return handlers.UserInfoData{}, err
}
if err == nil {
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)
if err != nil {
data.Session = &session.Session{Id: ss.ID}
}
data.User, err = p.getUser(r.Context(), data.Session.GetUserId())
if err != nil {
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)

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 Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
@ -20,50 +22,66 @@ export const SessionDetails: FC<SessionDetailsProps> = ({
profile,
}) => {
return (
<Section title="User Details">
<Stack spacing={3}>
<TableContainer>
<Table size="small">
<TableBody>
<TableRow>
<TableCell width={"18%"} variant="head">
Session ID
</TableCell>
<TableCell align="left">
<IDField value={session?.id} />
</TableCell>
</TableRow>
<TableRow>
<TableCell variant="head">User ID</TableCell>
<TableCell align="left">
<IDField
value={session?.userId || `${profile?.claims?.sub}`}
/>
</TableCell>
</TableRow>
<TableRow>
<TableCell variant="head">Expires At</TableCell>
<TableCell align="left">{session?.expiresAt || ""}</TableCell>
</TableRow>
{Object.entries(session?.claims || {}).map(([key, values]) => (
<ClaimRow
key={`session/${key}`}
claimKey={key}
claimValue={values}
/>
))}
{Object.entries(profile?.claims || {}).map(([key, value]) => (
<ClaimRow
key={`profile/${key}`}
claimKey={key}
claimValue={value}
/>
))}
</TableBody>
</Table>
</TableContainer>
</Stack>
</Section>
<>
{session?.id ? (
<Section title="User Details">
<Stack spacing={3}>
<TableContainer>
<Table size="small">
<TableBody>
<TableRow>
<TableCell width={"18%"} variant="head">
Session ID
</TableCell>
<TableCell align="left">
<IDField value={session?.id} />
</TableCell>
</TableRow>
<TableRow>
<TableCell variant="head">User ID</TableCell>
<TableCell align="left">
<IDField
value={
session?.userId || `${profile?.claims?.sub || ""}`
}
/>
</TableCell>
</TableRow>
<TableRow>
<TableCell variant="head">Expires At</TableCell>
<TableCell align="left">
{session?.expiresAt || ""}
</TableCell>
</TableRow>
{Object.entries(session?.claims || {}).map(
([key, values]) => (
<ClaimRow
key={`session/${key}`}
claimKey={key}
claimValue={values}
/>
)
)}
{Object.entries(profile?.claims || {}).map(([key, value]) => (
<ClaimRow
key={`profile/${key}`}
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;