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

Clear site data on logout #232

Merged
merged 7 commits into from
Dec 5, 2023
Merged

Conversation

phantomjinx
Copy link
Member

Since the header "Clear-Site-Data" is a server response header, the app must be directed to a landing page on logout that will allow this header to be communicated.

Provides a redirect page that when the user does a logout then are redirected first to the /logout url. This displays a "Going to provider login" page that countsdown then redirects after 5 seconds (or if the user clicks the link directly). This page provides the "Clear-Site-Data" header when called and clears the users storage for the domain.

@phantomjinx phantomjinx requested a review from tadayosi December 3, 2023 22:09
@phantomjinx phantomjinx self-assigned this Dec 3, 2023
@phantomjinx
Copy link
Member Author

hawtio-logout-redirect.mp4

* Since the Clear-Site-Data header is a server header, we must provide a
  server-based /logout page to redirect to. However, we want this page to
  then redirect automatically to the given login provider page

* webpack.config.js
 * Provides a server-side redirect in the oAuthApp devServer that
   implements a landing page for the logout, complete with the server
   header

* redirectlogin.html
 * Implementation of the /logout oAuthApp page, which provides a countdown
   to redirect to the search param provided 'redirect_uri' page
 * Also provides a direct immediately link
 * If there is no 'redirect_uri' parameter then an error is displayed. It
   is expected that servers will not allow this url to be displayed on its
   own.

* urls.ts
 * Provides common functions for testing for a /logout url if it exists
   and redirect()

* osoauth-service.ts
 * Differentiate between logout and login operations since the former needs
   to clear storage and redirect to /login endpoint
 * tryLogin function to try redirecting to /login page directly

* openshift/support.ts
* form-service.ts
 * When a logout occurs, the login url is built then passed to
   logoutRedirect. If the /logout endpoint is available then redirects to
   that; otherwise redirects directly to login url
@phantomjinx phantomjinx force-pushed the logout-redirect branch 2 times, most recently from f9f348f to 0851852 Compare December 3, 2023 22:16
* form-auth-login-service.ts
 * Uses the common redirect function now provided by urls.ts

* ouath-service.ts
 * adds in missed-out necessary 'await'
* Dockerfile
  * Copies production version of redirectlogin.html to container image

* docker/*
  * Modifies nginx config to respond to /logout location with html page
    complete with the response headers
Copy link
Member

@tadayosi tadayosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments we need to consider.

docker/nginx-gateway-k8s.conf.template Outdated Show resolved Hide resolved
docker/nginx.conf Outdated Show resolved Hide resolved
docker/redirectlogin.html Outdated Show resolved Hide resolved
docker/nginx-gateway.conf.template Outdated Show resolved Hide resolved
packages/oauth-app/webpack.config.js Outdated Show resolved Hide resolved
packages/oauth/src/form/form-service.ts Outdated Show resolved Hide resolved
* Synchronous function should not require it and since createLogin uses
  tryLogin rather than doLogout, the async redirection is not executed
  by it anymore
* oauth
 * Adds global var for centralising endpoint value
 * Updates the endpoint target to be /auth/logout rather than /logout

* oauth-app / online-shell
 * Updates webpack config of dev server to handle /auth/logout and to
   redirect directly rather than going to a landing page
 * Landing page removed

* docker
 * Removes landing page from Dockerfile
 * Adds JS function for decoding URIs to njinx.js. Since pure njinx lacks
   ability to decode a URI this is essential to ensure that the encoded
   url encapsulated in the redirect_uri parameter is properly processed
 * Updates nginx config to provide 'decodeRedirectURI' function and
   uses in /auth/logout location.
@phantomjinx
Copy link
Member Author

So one thing to note ...

In order for nginx to be able to successfully redirect to the login provider page, a conversion has to be performed to decode the URI encapsulated in the redirect_uri query parameter. 'Pure' nginx is not capable of performing this so the only serviceable way of achieving this is to use a custom function in the njinx.js to call decodeUriComponent(). The result is then returned. This is not ideal but the only mechanism that does not require installing more modules in nginx.

@phantomjinx phantomjinx requested a review from tadayosi December 4, 2023 23:02
Copy link
Member

@tadayosi tadayosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment but otherwise it looks good to me.

* Remove async but need to conform with interface
@phantomjinx phantomjinx merged commit dc804f2 into hawtio:main Dec 5, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants