Sign up for Hasura Newsletter
Loading...

Configuración del secreto de JWT

En esta parte, analizaremos cómo configurar el secreto de JWT.

Siga estas instrucciones para configurar el servidor de autenticación.

Autentique JWT mediante el uso del motor de GraphQL

El motor de GraphQL viene con la autenticación de JWT integrada. Necesitará iniciar el motor con el mismo secreto/clave que el servidor de autenticación de JWT utilizando la variable de entorno HASURA_GRAPHQL_JWT_SECRET. Lea más en docs

Tenga en cuenta que también necesita configurar la variable de entorno HASURA_GRAPHQL_ADMIN_SECRET. Considere esto como la contraseña para tener el control de administrador sobre el proyecto. Lea más sobre cómo configurar una nueva variable de entorno en un proyecto de Hasura Cloud.

Un comando de muestra CURL utilizando el token anterior sería:

curl -X POST \
https://ready-panda-91.hasura.app/v1/graphql \
-H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxIiwibmFtZSI6InRlc3QxMjMiLCJpYXQiOjE1NDAzNzY4MTUuODUzLCJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsiZWRpdG9yIiwidXNlciIsIm1vZCJdLCJ4LWhhc3VyYS11c2VyLWlkIjoiMSIsIngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1yb2xlIjoidXNlciJ9fQ.w9uj0FtesZOFUnwYT2KOWHr6IKWsDRuOC9G2GakBgMI' \
-H 'Content-Type: application/json' \
-d '{ "query": "{ users { id } }" }'

Ahora puede probar esto mediante la navegación a la consola y la realización de consultas sin el secreto de administrador. Debería obtener un error.

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin