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,10 +67,7 @@ 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) data.Session, data.IsImpersonated, err = p.getSession(r.Context(), ss.ID)
if err != nil { if err != nil {
data.Session = &session.Session{Id: ss.ID} data.Session = &session.Session{Id: ss.ID}
@ -80,6 +77,7 @@ func (p *Proxy) getUserInfoData(r *http.Request) (handlers.UserInfoData, error)
if err != nil { if err != nil {
data.User = &user.User{Id: data.Session.GetUserId()} data.User = &user.User{Id: data.Session.GetUserId()}
} }
}
data.WebAuthnCreationOptions, data.WebAuthnRequestOptions, _ = p.webauthn.GetOptions(r) data.WebAuthnCreationOptions, data.WebAuthnRequestOptions, _ = p.webauthn.GetOptions(r)
data.WebAuthnURL = urlutil.WebAuthnURL(r, urlutil.GetAbsoluteURL(r), state.sharedKey, r.URL.Query()) data.WebAuthnURL = urlutil.WebAuthnURL(r, urlutil.GetAbsoluteURL(r), state.sharedKey, r.URL.Query())

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,6 +22,8 @@ export const SessionDetails: FC<SessionDetailsProps> = ({
profile, profile,
}) => { }) => {
return ( return (
<>
{session?.id ? (
<Section title="User Details"> <Section title="User Details">
<Stack spacing={3}> <Stack spacing={3}>
<TableContainer> <TableContainer>
@ -37,21 +41,27 @@ export const SessionDetails: FC<SessionDetailsProps> = ({
<TableCell variant="head">User ID</TableCell> <TableCell variant="head">User ID</TableCell>
<TableCell align="left"> <TableCell align="left">
<IDField <IDField
value={session?.userId || `${profile?.claims?.sub}`} value={
session?.userId || `${profile?.claims?.sub || ""}`
}
/> />
</TableCell> </TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell variant="head">Expires At</TableCell> <TableCell variant="head">Expires At</TableCell>
<TableCell align="left">{session?.expiresAt || ""}</TableCell> <TableCell align="left">
{session?.expiresAt || ""}
</TableCell>
</TableRow> </TableRow>
{Object.entries(session?.claims || {}).map(([key, values]) => ( {Object.entries(session?.claims || {}).map(
([key, values]) => (
<ClaimRow <ClaimRow
key={`session/${key}`} key={`session/${key}`}
claimKey={key} claimKey={key}
claimValue={values} claimValue={values}
/> />
))} )
)}
{Object.entries(profile?.claims || {}).map(([key, value]) => ( {Object.entries(profile?.claims || {}).map(([key, value]) => (
<ClaimRow <ClaimRow
key={`profile/${key}`} key={`profile/${key}`}
@ -64,6 +74,14 @@ export const SessionDetails: FC<SessionDetailsProps> = ({
</TableContainer> </TableContainer>
</Stack> </Stack>
</Section> </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;