You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
This changes introduce two ways of changing the connection credentials in a driver instance, each of them solving a different use case.
Token Expiration / Change Credentials for the whole driver instance
This use case is related to the issue #993 in the repository. For solving this, the driver is now able to receive a AuthTokenManager in the driver creation. This interface enables the user code provide new auth tokens to the driver and be notified by token expiration failures.
For simplifying the usage, the driver also provides a default implementation of AuthTokenManager which can be created with neo4j. expirationBasedAuthTokenManager and receives a function for renewing the auth token as parameters.
Example:
importneo4j,{AuthToken}from'neo4j-driver'/** * Method called whenever the driver needs to refresh the token. * * The refresh will happen if the driver is notified by the server * about a token expiration or if the `Date.now() > tokenData.expiry` * * Important, the driver will block all the connections creation until * this function resolves the new auth token. */asyncfunctionfetchAuthTokenFromMyProvider(){constbearer: string=awaitmyProvider.getBearerToken()consttoken: AuthToken=neo4j.auth.bearer(bearer)constexpiration: Date=myProvider.getExpiryDate()return{
token,// if expiration is not provided, // the driver will only fetch a new token when a failure happens
expiration
}}constdriver=neo4j.driver('neo4j://localhost:7687',neo4j.expirationBasedAuthTokenManager({tokenProvider: fetchAuthTokenFromMyProvider}))
User Switching
In this scenario, different credentials can be configured in a session providing a way for change the user context for the session. For using this feature, it needed to check if your server supports session auth by calling driver.supportsSessionAuth().
Example:
importneo4jfrom'neo4j-driver'constdriver=neo4j.driver('neo4j://localhost:7687',neo4j.auth.basic('neo4j','password'))constsessionWithUserB=driver.session({database: 'neo4j',auth: neo4j.auth.basic('userB','userBpassword')})try{// run some queries as userBconstresult=awaitsessionWithUserB.executeRead(tx=>tx.run('RETURN 1'))}finally{// close the session as usualawaitsessionWithUserB.close()}
Hi, apologies if this is the wrong place to ask. Thank you, been looking forward to this work. It looks like this missed the 5.7 release. Is it feasible to put out 5.8 release so we can test out this API preview?
I know this feature is in preview, so happy to wait. I wanted to try this out since we've had problems in the past with Neo4jError: LDAP authorization info expired. We've worked around it by catching that particular error and retrying, but this felt like it might be a cleaner solution.
I believe the typescript types may not all be updated. It seems the second argument to neo4j.driver still only accepts AuthToken.
Argument of type 'AuthTokenManager' is not assignable to parameter of type 'AuthToken'. Type 'AuthTokenManager' is missing the following properties from type 'AuthToken': scheme, credentials
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.
This changes introduce two ways of changing the connection credentials in a driver instance, each of them solving a different use case.
Token Expiration / Change Credentials for the whole driver instance
This use case is related to the issue #993 in the repository. For solving this, the driver is now able to receive a
AuthTokenManager
in the driver creation. This interface enables the user code provide new auth tokens to the driver and be notified by token expiration failures.For simplifying the usage, the driver also provides a default implementation of
AuthTokenManager
which can be created withneo4j. expirationBasedAuthTokenManager
and receives a function for renewing the auth token as parameters.Example:
User Switching
In this scenario, different credentials can be configured in a session providing a way for change the user context for the session. For using this feature, it needed to check if your server supports session auth by calling
driver.supportsSessionAuth()
.Example: