Hasura 身份验证 Passport.js Auth Webhook 不起作用
Hasura Authentication Passport.js Auth Webhook does not work
我尝试使用 Passport.js Auth Webhook 样板 here to setup a custom authentication in my app. I followed the Readme and tried to test the setup locally first. I could successfully create users via Postman using the /signup
API and also use the /login
API to receive the token. I implemented a simple login form and tried to made a request to the /login
API with username and password from an already created user, then I received the response with the token and saved it in the local storage to add the Authorization: Bearer <token>
to the header. Then when I was trying to access a page where I've made a graphQL request I only got this Error: GraphQL error: Internal Server Error
. Without using the authentication handling via the webhook, it worked without problems by using the HASURA_GRAPHQL_ADMIN_SECRET
in the header. This I've tried yesterday. Today when I start all the servers locally like yesterday I can't even get a successful request via Postman. What's also important to mention I've added the HASURA_GRAPHQL_AUTH_HOOK
-> http://localhost:8081/webhook
(I removed the admin secret from the authorization header to enable the webhook) and also set permissions for the user to access the todos table like shown here
我可能做错了什么?这是我的设置。如果您需要更多信息,请告诉我
这是为了获取 Hasura GraphQL 引擎和 Postgres 运行 作为 Docker 容器,显示 here(我的 docker-compose.yaml
文件):
version: '3.6'
services:
postgres:
image: postgres
restart: always
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
graphql-engine:
image: hasura/graphql-engine:v1.0.0-beta.6
ports:
- "8080:8080"
depends_on:
- "postgres"
restart: always
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_ADMIN_SECRET: secret
HASURA_GRAPHQL_AUTH_HOOK: http://localhost:8081/webhook
volumes:
db_data:
passport.js 样板项目 运行 http://localhost:8081
hasura/graphql-engine 在 http://localhost:8080
上 运行
主要应用是 运行 http://localhost:3000
所以有两个问题:
就像评论中写的 @praveenweb 一样(在我的例子中是 mac)我不得不将容器的 localhost
替换为 host.docker.internal
访问主机 machine 的身份验证服务器。所以而不是 HASURA_GRAPHQL_AUTH_HOOK: http://localhost:8081/webhook
-> HASURA_GRAPHQL_AUTH_HOOK: http://host.docker.internal:8081/webhook
之所以第二天没有成功响应,是因为我完全忘记在环境变量中设置DATABASE_URL
,如图here。所以就我而言 export DATABASE_URL=postgres://postgres:@localhost:5432/postgres
现在一切正常。希望这对其他人也有帮助。
我尝试使用 Passport.js Auth Webhook 样板 here to setup a custom authentication in my app. I followed the Readme and tried to test the setup locally first. I could successfully create users via Postman using the /signup
API and also use the /login
API to receive the token. I implemented a simple login form and tried to made a request to the /login
API with username and password from an already created user, then I received the response with the token and saved it in the local storage to add the Authorization: Bearer <token>
to the header. Then when I was trying to access a page where I've made a graphQL request I only got this Error: GraphQL error: Internal Server Error
. Without using the authentication handling via the webhook, it worked without problems by using the HASURA_GRAPHQL_ADMIN_SECRET
in the header. This I've tried yesterday. Today when I start all the servers locally like yesterday I can't even get a successful request via Postman. What's also important to mention I've added the HASURA_GRAPHQL_AUTH_HOOK
-> http://localhost:8081/webhook
(I removed the admin secret from the authorization header to enable the webhook) and also set permissions for the user to access the todos table like shown here
我可能做错了什么?这是我的设置。如果您需要更多信息,请告诉我
这是为了获取 Hasura GraphQL 引擎和 Postgres 运行 作为 Docker 容器,显示 here(我的 docker-compose.yaml
文件):
version: '3.6'
services:
postgres:
image: postgres
restart: always
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
graphql-engine:
image: hasura/graphql-engine:v1.0.0-beta.6
ports:
- "8080:8080"
depends_on:
- "postgres"
restart: always
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_ADMIN_SECRET: secret
HASURA_GRAPHQL_AUTH_HOOK: http://localhost:8081/webhook
volumes:
db_data:
passport.js 样板项目 运行 http://localhost:8081
hasura/graphql-engine 在 http://localhost:8080
主要应用是 运行 http://localhost:3000
所以有两个问题:
就像评论中写的 @praveenweb 一样(在我的例子中是 mac)我不得不将容器的
localhost
替换为host.docker.internal
访问主机 machine 的身份验证服务器。所以而不是HASURA_GRAPHQL_AUTH_HOOK: http://localhost:8081/webhook
->HASURA_GRAPHQL_AUTH_HOOK: http://host.docker.internal:8081/webhook
之所以第二天没有成功响应,是因为我完全忘记在环境变量中设置
DATABASE_URL
,如图here。所以就我而言export DATABASE_URL=postgres://postgres:@localhost:5432/postgres
现在一切正常。希望这对其他人也有帮助。