Graphql-engine: How can i create API token's for my users ?

Created on 27 Jan 2020  路  4Comments  路  Source: hasura/graphql-engine

I using firebase auth, and i want to create API tokens for my users (role user) with role 'API'. How can I implement this?

question

All 4 comments

Firebase tokens expire in 1 hour. It's not good for me.
I鈥檓 thinking about how to save tokens in the database and compare their _exists before the request. How to configure Hasura to work on authorization and without authorization?

You can configure an 'unauthenticated' role and then define permissions for that role: https://docs.hasura.io/1.0/graphql/manual/auth/authentication/unauthenticated-access.html.

Yes ! This is my solution.
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: "anonymous"

And permissions

{
  "_and":[
    {
      "_exists":{
        "_table":{
          "name":"user",
          "schema":"public"
        },
        "_where":{
          "id":{
            "_eq":"X-Hasura-User-Id"
          }
        }
      }
    },
    {
      "_exists":{
        "_table":{
          "name":"token",
          "schema":"public"
        },
        "_where":{
          "_and":[
            {
              "id":{
                "_eq":"X-Hasura-Token-Id"
              }
            },
            {
              "user_id":{
                "_eq":"X-Hasura-User-Id"
              }
            }
          ]
        }
      }
    }
  ]
}
Was this page helpful?
0 / 5 - 0 ratings