Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logout from both idp and app #60

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 81 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@comunica/core": "^2.8.1",
"@inrupt/solid-client": "^1.23.3",
"@inrupt/solid-client-access-grants": "^3.0.4",
"@inrupt/solid-client-authn-browser": "^2.0.0",
"@inrupt/solid-client-authn-node": "^2.0.0",
"@inrupt/solid-client-authn-browser": "^2.2.4",
"@inrupt/solid-client-authn-node": "^2.2.4",
"@inrupt/solid-client-vc": "^1.0.0",
"@popperjs/core": "^2.11.8",
"@rdfjs/types": "^1.1.0",
Expand Down
42 changes: 36 additions & 6 deletions src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ export default function Header({
}) {
const { logout, session } = useContext(SessionContext);

const isUrl = (candidateUrl: string | URL) => {
try {
// If url is not URL-shaped, this will throw
new URL(candidateUrl);
return true;
} catch (_e) {
return false;
}
};

/**
* Handles the logout process of the application, which can be of two types: app logout and idp logout.
*
* For those OPs supporting Solid-OIDC Client Identifiers, the logout will log users out of their OP by
* redirecting them away from the application. For users to be redirected back, a post-logout URL must
* be included. This is handled by the IDP logout.
* For OPs that are not Solid-OIDC enabled, the log out will just clear any session data from the browser:
* it does not log the users out of their OP nor redirect them away. This is handled by the app logout.
*
* If the session client ID is a URL, the OP is Solid-OIDC enabled; otherwise, it is not.
*/
const handleLogout = async () => {
if (
garciafdezpatricia marked this conversation as resolved.
Show resolved Hide resolved
session.info.clientAppId !== undefined &&
isUrl(session.info.clientAppId)
) {
await logout({
logoutType: "idp",
postLogoutUrl: new URL(window.origin).href,
});
} else {
await logout({ logoutType: "app" });
}
};

return (
<header className={styles.header}>
<div className={styles["header-top"]}>
Expand All @@ -44,12 +79,7 @@ export default function Header({
<Button
variant="text"
data-testid="logout-button"
onClick={() =>
logout({
logoutType: "idp",
postLogoutUrl: new URL("/", window.location.href).toString(),
})
}
onClick={() => handleLogout()}
garciafdezpatricia marked this conversation as resolved.
Show resolved Hide resolved
className={styles["logout-button"]}
>
Logout
Expand Down