1+ import { createDriver } from 'use-neo4j' ;
12import { initializeSSO } from '../component/sso/SSOUtils' ;
23import { DEFAULT_SCREEN , Screens } from '../config/ApplicationConfig' ;
34import { setDashboard } from '../dashboard/DashboardActions' ;
@@ -43,9 +44,6 @@ import {
4344} from './ApplicationActions' ;
4445import { setLoggingMode , setLoggingDatabase , setLogErrorNotification } from './logging/LoggingActions' ;
4546import { version } from '../modal/AboutModal' ;
46- import neo4j , { auth , authTokenManagers } from 'neo4j-driver' ;
47- import type { Neo4jScheme } from 'use-neo4j/dist/neo4j-config.interface' ;
48- import { SSOProviderOriginal , handleRefreshingToken } from 'neo4j-client-sso' ;
4947import { applicationIsStandalone } from './ApplicationSelectors' ;
5048import { applicationGetLoggingSettings } from './logging/LoggingSelectors' ;
5149import { createLogThunk } from './logging/LoggingThunk' ;
@@ -56,47 +54,6 @@ import { createUUID } from '../utils/uuid';
5654 * Several actions/other thunks may be dispatched from here.
5755 */
5856
59- export const createDriver = (
60- scheme : Neo4jScheme ,
61- host : string ,
62- port : string | number ,
63- username ?: string ,
64- password ?: string ,
65- config ?: { userAgent ?: string } ,
66- ssoProviders : SSOProviderOriginal [ ] = [ ]
67- ) => {
68- if ( ssoProviders . length > 0 ) {
69- const authTokenMgr = authTokenManagers . bearer ( {
70- tokenProvider : async ( ) => {
71- const credentials = await handleRefreshingToken ( ssoProviders ) ;
72- const token = auth . bearer ( credentials . password ) ;
73- // Get the expiration from the JWT's payload, which is a JSON string encoded
74- // using base64. You could also use a JWT parsing lib
75- const [ , payloadBase64 ] = credentials . password . split ( '.' ) ;
76- const payload : unknown = JSON . parse ( window . atob ( payloadBase64 ?? '' ) ) ;
77- let expiration : Date ;
78- if ( typeof payload === 'object' && payload !== null && 'exp' in payload ) {
79- expiration = new Date ( Number ( payload . exp ) * 1000 ) ;
80- } else {
81- expiration = new Date ( ) ;
82- }
83-
84- return {
85- expiration,
86- token,
87- } ;
88- } ,
89- } ) ;
90- return neo4j . driver ( `${ scheme } ://${ host } :${ port } ` , authTokenMgr , config ) ;
91- }
92-
93- if ( ! username || ! password ) {
94- return neo4j . driver ( `${ scheme } ://${ host } :${ port } ` ) ;
95- }
96-
97- return neo4j . driver ( `${ scheme } ://${ host } :${ port } ` , neo4j . auth . basic ( username , password ) , config ) ;
98- } ;
99-
10057/**
10158 * Establish a connection to Neo4j with the specified credentials. Open/close the relevant windows when connection is made (un)successfully.
10259 * @param protocol - the neo4j protocol (e.g. bolt, bolt+s, neo4j+s, ...)
@@ -105,24 +62,14 @@ export const createDriver = (
10562 * @param database - the Neo4j database to connect to.
10663 * @param username - Neo4j username.
10764 * @param password - Neo4j password.
108- * @param SSOProviders - List of available SSO providers
10965 */
11066export const createConnectionThunk =
111- ( protocol , url , port , database , username , password , SSOProviders = [ ] ) =>
112- ( dispatch : any , getState : any ) => {
67+ ( protocol , url , port , database , username , password ) => ( dispatch : any , getState : any ) => {
11368 const loggingState = getState ( ) ;
11469 const loggingSettings = applicationGetLoggingSettings ( loggingState ) ;
11570 const neodashMode = applicationIsStandalone ( loggingState ) ? 'Standalone' : 'Editor' ;
11671 try {
117- const driver = createDriver (
118- protocol ,
119- url ,
120- port ,
121- username ,
122- password ,
123- { userAgent : `neodash/v${ version } ` } ,
124- SSOProviders
125- ) ;
72+ const driver = createDriver ( protocol , url , port , username , password , { userAgent : `neodash/v${ version } ` } ) ;
12673 // eslint-disable-next-line no-console
12774 console . log ( 'Attempting to connect...' ) ;
12875 const validateConnection = ( records ) => {
@@ -561,7 +508,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState:
561508 dispatch ( setAboutModalOpen ( false ) ) ;
562509 dispatch ( setConnected ( false ) ) ;
563510 dispatch ( setWelcomeScreenOpen ( false ) ) ;
564- const success = await initializeSSO ( state . application . cachedSSODiscoveryUrl , ( credentials , ssoProviders ) => {
511+ const success = await initializeSSO ( state . application . cachedSSODiscoveryUrl , ( credentials ) => {
565512 if ( standalone ) {
566513 // Redirected from SSO and running in viewer mode, merge retrieved config with hardcoded credentials.
567514 dispatch (
@@ -571,8 +518,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState:
571518 config . standalonePort ,
572519 config . standaloneDatabase ,
573520 credentials . username ,
574- credentials . password ,
575- ssoProviders
521+ credentials . password
576522 )
577523 ) ;
578524 dispatch (
@@ -582,8 +528,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState:
582528 config . standalonePort ,
583529 config . standaloneDatabase ,
584530 credentials . username ,
585- credentials . password ,
586- ssoProviders
531+ credentials . password
587532 )
588533 ) ;
589534 } else {
@@ -595,8 +540,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState:
595540 state . application . connection . port ,
596541 state . application . connection . database ,
597542 credentials . username ,
598- credentials . password ,
599- ssoProviders
543+ credentials . password
600544 )
601545 ) ;
602546 dispatch ( setConnected ( true ) ) ;
0 commit comments