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

feat: Logging out #1244

Merged
merged 23 commits into from
May 2, 2023
Merged

feat: Logging out #1244

merged 23 commits into from
May 2, 2023

Conversation

mofojed
Copy link
Member

@mofojed mofojed commented Apr 24, 2023

  • Write auth plugin components as wrappers
    • Allows plugins to always be mounted and control the transition to loading the app
    • Needed to ensure keycloak plugin can wipe token on logout
  • Refactor auth plugins to just use AuthPluginBase
    • There was a lot of the same code, just refactored it into one common base
    • Also added a useContextOrThrow hook
  • Added login screen for AuthPluginPsk
    • Took the LoginAnimation from Enterprise, renamed to RandomAreaPlotAnimation
    • Added a Login and LoginForm components to allow others to reuse if desired
    • Also stores the pre-shared key as a cookie after successful login
  • Add broadcast channel for notifying other tabs about login/logout
    • Notifies after successful login, or when logout button is pressed
  • Added permission for canLogout (since you can't logout when anonymous
  • Add context providers for overriding user info and permissions (used by auth plugins)

@mofojed mofojed requested a review from mattrunyon April 27, 2023 15:18
@mofojed mofojed self-assigned this Apr 27, 2023
@mofojed mofojed marked this pull request as ready for review April 27, 2023 15:19
@mofojed
Copy link
Member Author

mofojed commented Apr 27, 2023

Getting an error when trying to import from auth-keycloak:

@deephaven/js-plugin-auth-keycloak: build started...
@deephaven/js-plugin-auth-keycloak: ✓ 6190 modules transformed.
@deephaven/js-plugin-auth-keycloak: Could not resolve "./Login.css" from "../../node_modules/@deephaven/auth-plugins/dist/Login.js"
@deephaven/js-plugin-auth-keycloak: file: /home/bender/dev/deephaven/deephaven-js-plugins/node_modules/@deephaven/auth-plugins/dist/Login.js

@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Merging #1244 (9d018fd) into main (0e286bd) will decrease coverage by 0.12%.
The diff coverage is 45.64%.

@@            Coverage Diff             @@
##             main    #1244      +/-   ##
==========================================
- Coverage   45.69%   45.57%   -0.12%     
==========================================
  Files         473      484      +11     
  Lines       33713    34077     +364     
  Branches     8457     8532      +75     
==========================================
+ Hits        15404    15531     +127     
- Misses      18258    18495     +237     
  Partials       51       51              
Flag Coverage Δ
unit 45.57% <45.64%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/app-utils/src/components/useConnection.ts 0.00% <0.00%> (ø)
packages/app-utils/src/components/usePlugins.ts 0.00% <0.00%> (ø)
...s/app-utils/src/plugins/remote-component.config.ts 100.00% <ø> (ø)
packages/auth-plugins/src/AuthPlugin.ts 0.00% <ø> (ø)
packages/code-studio/src/main/AppInit.tsx 0.00% <0.00%> (ø)
packages/code-studio/src/settings/SettingsMenu.tsx 7.93% <0.00%> (-3.18%) ⬇️
packages/components/src/LoadingOverlay.tsx 0.00% <0.00%> (ø)
...ges/jsapi-components/src/RefreshTokenBootstrap.tsx 0.00% <0.00%> (ø)
packages/jsapi-components/src/RefreshTokenUtils.ts 0.00% <0.00%> (ø)
.../jsapi-components/src/useInitializeViewportData.ts 88.88% <ø> (ø)
... and 26 more

... and 1 file with indirect coverage changes

__mocks__/react-transition-group.js Outdated Show resolved Hide resolved
__mocks__/react-transition-group.js Outdated Show resolved Hide resolved
Comment on lines 29 to 32
'react-transition-group': path.join(
__dirname,
'./__mocks__/react-transition-group.js'
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm I'm not sure this should be needed based on the Jest docs. They say mocking node modules from __mocks__ adjacent to node_modules is an automatic mock here. This is different from mocking user modules

It might be the way we have jest set up. Honestly, I'm not sure the jest projects is all that helpful even though we're running from the root. I'd be interested to see how often we use it as developers for more than disabling the linter tests. I think that I set it up that way b/c some packages had different Jest setup requirements, but now I think it's basically code-studio and then every other package shares a config basically

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea if we don't have this here the mock doesn't get applied and all the tests fail. Guess it's how we have jest set up.
The automatic mocking happens for __mocks__ folders next to the node_modules folders of our packages, but not at the root it would appear.
I'm not too invested in figuring it out beyond that, perhaps we switch to vitest at some point.

package-lock.json Outdated Show resolved Hide resolved
packages/code-studio/src/main/AppInit.tsx Show resolved Hide resolved
packages/code-studio/src/main/AppMainContainer.tsx Outdated Show resolved Hide resolved
packages/jsapi-components/src/RefreshTokenUtils.ts Outdated Show resolved Hide resolved
packages/jsapi-components/src/RefreshTokenUtils.ts Outdated Show resolved Hide resolved
packages/jsapi-components/src/useBroadcastChannel.ts Outdated Show resolved Hide resolved
mofojed added 13 commits May 1, 2023 08:56
- Just added what was already part of app-utils
- Add tests for AuthPluginBase
- Add mock for react-transition-gruop
- Just cleaning up the ternary op
- Probably not a problem, as we write the cookie, but on the outside chance someone modified their cookies should handle it safely
- Also refactored deleting the refresh token a bit
- Seems to work fine, not sure what the previous comment was complaining about
- Is imported by the PSK plugin, now it appears correctly.
@mofojed mofojed force-pushed the 1239-logging-out branch from 6330d6e to 466ffc9 Compare May 1, 2023 15:08
@mofojed mofojed requested a review from mattrunyon May 1, 2023 18:22
@@ -1,5 +1,6 @@
import React from 'react';
import { RandomAreaPlotAnimation } from '@deephaven/components';
import Logo from './logo.png';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess in DHC we won't allow changing the logo? Or we just recommend a custom auth plugin for that?

I know it's something we offer in DHE by just replacing the logo file.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is something we do with DHE, which has some server side configuration: https://github.com/deephaven-ent/iris/blob/d6950c95398cbe9a400eca8ba90e11201dcdae7c/web/server-frontend/src/main/java/com/illumon/iris/web/server/AbstractIrisWebServer.java#L170
We don't have that same configuration on the DHC side.

That being said, I'll wire it up the same on the client. Just means the logo is in 3 public paths (ide, embed-grid, embed-chart) instead of just being packaged with auth plugins.

And yes, a custom auth plugin would be able to customize whatever.

packages/jsapi-utils/src/MessageUtils.ts Outdated Show resolved Hide resolved
@mofojed mofojed requested a review from mattrunyon May 1, 2023 22:44
Copy link
Collaborator

@mattrunyon mattrunyon left a comment

Choose a reason for hiding this comment

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

Looks good. Just confirming we intentionally remove the PSK from the URL after PSK auth is complete? Still refreshes fine, just making sure that's intentional since I thought that before this change the key stayed in the URL

@mofojed
Copy link
Member Author

mofojed commented May 2, 2023

Correct. We actually remove it from the URL right away. It is stored as a cookie so refresh will work correctly.

@mofojed mofojed merged commit 769d753 into deephaven:main May 2, 2023
@mofojed mofojed deleted the 1239-logging-out branch May 2, 2023 18:08
@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants