首页 > 解决方案 > @neo4j/graphql:auth JWT 未配置

问题描述

我正在尝试从一个简单的 dockerized nodejs 应用程序访问 dockerized neo4j。

以下是我的docker-compose配置:

version: '2.1'

services:
  neo4j:
    image: neo4j:latest
    container_name: ltimdb_neo4j
    ports: 
      - "7474:7474"
      - "7687:7687"
    volumes: 
      - $HOME/data:/data
      - $HOME/neo4j/logs:/logs
      - $HOME/neo4j/import:/var/lib/neo4j/import
      - $HOME/plugins:/plugins
    environment:
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
      - NEO4JLABS_PLUGINS=\[\"apoc\"\]
      - NEO4J_AUTH=neo4j/ltimdb
    networks:
      - default
    restart: always
      
  graphql:
    build: ./ltimdb-graphql-api-server
    container_name: ltimdb_graphql
    depends_on:
      - neo4j
    environment:
      - NEO4J_URI=bolt://neo4j:7687
      - NEO4J_USER=neo4j
      - NEO4J_PASSWORD=ltimdb
    ports:
      - "4000:4000"
    networks:
      - default
    restart: always

如您所见,我已经在启动 neo4j 并将适当的凭据传递给 nodejs 应用程序容器时更改了密码。但我仍然无法通过此设置访问数据库。相同的代码在没有 dockerization 的情况下可以工作,但之后无法工作。

我在我的应用程序中访问 neo4j,如下所示:

const driver = neo4j.driver(
  process.env.NEO4J_URI,
  neo4j.auth.basic(process.env.NEO4J_USER, process.env.NEO4J_PASSWORD)
);

我已经登录控制台NEO4J_URINEO4J_USERNEO4J_PASSWORD从应用程序中查看他们是否正确地访问了应用程序并且它的记录正常。

我在控制台上收到以下错误:

graphql_1  | 2021-06-16T08:43:22.736Z @neo4j/graphql:auth JWT not configured
graphql_1  | 2021-06-16T08:43:22.743Z @neo4j/graphql:execute About to execute Cypher:
graphql_1  | Cypher:
graphql_1  | MATCH (this:Movie)
graphql_1  | RETURN this { .title } as this
graphql_1  | Params:
graphql_1  | {}
neo4j_1    | 2021-06-16 08:43:22.950+0000 WARN  The client is unauthorized due to authentication failure.
graphql_1  | 2021-06-16T08:43:23.003Z @neo4j/graphql:execute Neo4jError: The client is unauthorized due to authentication failure.
graphql_1  | 
graphql_1  |     at captureStacktrace (/usr/src/app/node_modules/neo4j-driver-core/lib/result.js:239:17)
graphql_1  |     at new Result (/usr/src/app/node_modules/neo4j-driver-core/lib/result.js:59:23)
graphql_1  |     at newCompletedResult (/usr/src/app/node_modules/neo4j-driver-core/lib/transaction.js:372:12)
graphql_1  |     at Object.run (/usr/src/app/node_modules/neo4j-driver-core/lib/transaction.js:226:20)
graphql_1  |     at Transaction.run (/usr/src/app/node_modules/neo4j-driver-core/lib/transaction.js:98:34)
graphql_1  |     at /usr/src/app/node_modules/@neo4j/graphql/dist/utils/execute.js:63:108
graphql_1  |     at TransactionExecutor._safeExecuteTransactionWork (/usr/src/app/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:92:26)
graphql_1  |     at TransactionExecutor._executeTransactionInsidePromise (/usr/src/app/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:83:34)
graphql_1  |     at /usr/src/app/node_modules/neo4j-driver-core/lib/internal/transaction-executor.js:40:19
graphql_1  |     at new Promise (<anonymous>) {
graphql_1  |   constructor: [Function: Neo4jError],
graphql_1  |   code: 'Neo.ClientError.Security.Unauthorized'

另外,我想指出我没有@auth在我的 graphql 类型定义中使用注释,我猜这可能需要 JWT 身份验证。

请建议。TIA。

标签: javascriptnode.jsdockerneo4japollo-server

解决方案


推荐阅读