-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Core authentication plugins #1180
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0859753
Add support for AuthPlugins
mofojed a6065ff
Pass the auth config values to the login plugin
mofojed c128f82
Add core auth plugins to UI
mofojed 0ef2deb
Add some documentation to auth-plugin about usage
mofojed 8269b59
Add tests for auth plugins, examples to docs
mofojed 4f68c04
Only allow AuthPluginParent when authProvider=parent set
mofojed cffc364
Merge remote-tracking branch 'origin/main' into auth-plugins
mofojed 7cce112
WIP add a TODO to login in the embedded apps
mofojed 3361741
Pull plugins into their own package, plugin-utils
mofojed 231e0ef
Move loading plugins into it's own util function
mofojed a3750af
Merge remote-tracking branch 'origin/main' into auth-plugins
mofojed 77e6cff
Fix up conflicts after merging latest main
mofojed 716dd7c
Refactor some of the app initialization code
mofojed 54521f5
Move getClientOptions to the app-utils package
mofojed c1f89f9
Added initialization bootstrap to app-utils
mofojed 0959b1d
Fix up unit tests and style guide
mofojed fde0dea
Add AppBootstrap to embed-grid application
mofojed f5a1c92
Update embed-chart to use AppBootstrap
mofojed 9ac1104
Clean up app-utils based on self-review
mofojed e5a8fea
Fix plugins loading in embed-grid and embed-chart
mofojed 8cb5884
More cleanup on self-review
mofojed 6964acc
Cleanup after review
mofojed 4f7c5c4
Fix failing tests
mofojed 2a689a6
Add authentication keyword
mofojed 671a083
Merge remote-tracking branch 'origin/main' into auth-plugins
mofojed 0eac926
Add some unit tests for AppBootstrap
mofojed 6882a2f
Add a comment explaining why using useContext instead of usePlugins
mofojed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
| /dist | ||
|
|
||
| # misc | ||
| .vscode | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .project | ||
| .settings/ | ||
| .eslintcache | ||
| .stylelintcache | ||
|
|
||
| /public/vs | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| src/**/*.css |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # @deephaven/jsapi-utils | ||
|
|
||
| A library with some JS utility methods for interacting with the JSAPI. | ||
|
|
||
| ## Install | ||
|
|
||
| ```bash | ||
| npm install --save @deephaven/jsapi-utils | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| import { TableUtils } from '@deephaven/jsapi-utils'; | ||
|
|
||
| if (TableUtils.isDateType(columnType)) { | ||
| console.log('Date type', columnType); | ||
| } else if (TableUtils.isNumberType(columnType)) { | ||
| console.log('Number type', columnType); | ||
| } else { | ||
| console.log('Unrecognized type', columnType); | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const baseConfig = require('../../jest.config.base.cjs'); | ||
| const packageJson = require('./package'); | ||
|
|
||
| module.exports = { | ||
| ...baseConfig, | ||
| displayName: packageJson.name, | ||
| resetMocks: false, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| { | ||
| "name": "@deephaven/auth-core-plugins", | ||
| "version": "0.32.0", | ||
| "description": "Deephaven Auth Core Plugins", | ||
| "keywords": [ | ||
| "Deephaven", | ||
| "plugin", | ||
| "deephaven-js-plugin", | ||
| "auth", | ||
| "anonymous", | ||
| "parent", | ||
| "psk", | ||
| "Pre-shared key" | ||
| ], | ||
| "author": "Deephaven Data Labs LLC", | ||
| "license": "Apache-2.0", | ||
| "type": "module", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/deephaven/web-client-ui.git", | ||
| "directory": "packages/auth-plugin" | ||
| }, | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "source": "src/index.ts", | ||
| "engines": { | ||
| "node": ">=16" | ||
| }, | ||
| "scripts": { | ||
| "build": "cross-env NODE_ENV=production run-p build:*", | ||
| "build:babel": "babel ./src --out-dir ./dist --extensions \".ts,.tsx,.js,.jsx\" --source-maps --root-mode upward" | ||
| }, | ||
| "dependencies": { | ||
| "@deephaven/auth-plugin": "file:../auth-plugin", | ||
| "@deephaven/components": "file:../components", | ||
| "@deephaven/log": "file:../log", | ||
| "@deephaven/jsapi-bootstrap": "file:../jsapi-bootstrap", | ||
| "@deephaven/jsapi-types": "file:../jsapi-types" | ||
| }, | ||
| "devDependencies": { | ||
| "@deephaven/tsconfig": "file:../tsconfig", | ||
| "@types/react": "^17.0.2" | ||
| }, | ||
| "peerDependencies": { | ||
| "react": "^17.x" | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export const AUTH_HANDLER_TYPE_ANONYMOUS = | ||
| 'io.deephaven.auth.AnonymousAuthenticationHandler'; | ||
|
|
||
| export const AUTH_HANDLER_TYPE_PSK = | ||
| 'io.deephaven.authentication.psk.PskAuthenticationHandler'; | ||
|
mofojed marked this conversation as resolved.
|
||
109 changes: 109 additions & 0 deletions
109
packages/auth-core-plugins/src/AuthPluginAnonymous.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import React from 'react'; | ||
| import { act, render, screen } from '@testing-library/react'; | ||
| import { ApiContext } from '@deephaven/jsapi-bootstrap'; | ||
| import { dh } from '@deephaven/jsapi-shim'; | ||
| import AuthPluginAnonymous from './AuthPluginAnonymous'; | ||
| import { AUTH_HANDLER_TYPE_ANONYMOUS as AUTH_TYPE } from './AuthHandlerTypes'; | ||
|
|
||
| function makeCoreClient() { | ||
| return new dh.CoreClient('wss://test.mockurl.example.com'); | ||
| } | ||
|
|
||
| describe('availability tests', () => { | ||
| const client = makeCoreClient(); | ||
| const authConfigValues = new Map(); | ||
| it.each([ | ||
| [[AUTH_TYPE], true], | ||
| [['another.type', AUTH_TYPE], true], | ||
| [[], false], | ||
| [ | ||
| ['not-anonymous', `${AUTH_TYPE}.withsuffix`, `prefix.${AUTH_TYPE}`], | ||
| false, | ||
| ], | ||
| ])( | ||
| 'returns availability based on auth handlers: %s', | ||
| (authHandlers, result) => { | ||
| expect( | ||
| AuthPluginAnonymous.isAvailable(client, authHandlers, authConfigValues) | ||
| ).toBe(result); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| function expectLoading() { | ||
| expect(screen.queryByTestId('auth-anonymous-loading')).not.toBeNull(); | ||
| } | ||
|
|
||
| describe('component tests', () => { | ||
| const authConfigValues = new Map(); | ||
| it('attempts to login on mount, calls success', async () => { | ||
| const loginPromise = Promise.resolve(); | ||
| const onSuccess = jest.fn(); | ||
| const onFailure = jest.fn(); | ||
| const mockLogin = jest.fn(() => loginPromise); | ||
| const client = makeCoreClient(); | ||
| client.login = mockLogin; | ||
| render( | ||
| <ApiContext.Provider value={dh}> | ||
| <AuthPluginAnonymous.Component | ||
| authConfigValues={authConfigValues} | ||
| client={client} | ||
| onFailure={onFailure} | ||
| onSuccess={onSuccess} | ||
| /> | ||
| </ApiContext.Provider> | ||
| ); | ||
| expectLoading(); | ||
| expect(onSuccess).not.toHaveBeenCalled(); | ||
| expect(onFailure).not.toHaveBeenCalled(); | ||
| expect(mockLogin).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: dh.CoreClient.LOGIN_TYPE_ANONYMOUS, | ||
| }) | ||
| ); | ||
|
|
||
| await loginPromise; | ||
|
|
||
| expect(onSuccess).toHaveBeenCalled(); | ||
| expect(onFailure).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('attempts to login on mount, calls failure if login fails', async () => { | ||
| const error = 'Mock test error'; | ||
| const loginPromise = Promise.reject(error); | ||
| const onSuccess = jest.fn(); | ||
| const onFailure = jest.fn(); | ||
| const mockLogin = jest.fn(() => loginPromise); | ||
| const client = makeCoreClient(); | ||
| client.login = mockLogin; | ||
| render( | ||
| <ApiContext.Provider value={dh}> | ||
| <AuthPluginAnonymous.Component | ||
| authConfigValues={authConfigValues} | ||
| client={client} | ||
| onFailure={onFailure} | ||
| onSuccess={onSuccess} | ||
| /> | ||
| </ApiContext.Provider> | ||
| ); | ||
| expectLoading(); | ||
| expect(onSuccess).not.toHaveBeenCalled(); | ||
| expect(onFailure).not.toHaveBeenCalled(); | ||
| expect(mockLogin).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: dh.CoreClient.LOGIN_TYPE_ANONYMOUS, | ||
| }) | ||
| ); | ||
|
|
||
| await act(async () => { | ||
| try { | ||
| await loginPromise; | ||
| } catch (e) { | ||
| // We know it fails | ||
| } | ||
| }); | ||
|
|
||
| expect(onSuccess).not.toHaveBeenCalled(); | ||
| expect(onFailure).toHaveBeenCalledWith(error); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.