JWT Provider Service

Since setting up Auth0 or Firebase with Unity is a process in itself, we'd be setting up our own custom jwt provider!

It doesn't have the many useful features but it gets the job done. Let's get into it.

Glitch Set Up

I already created a Glitch project for this. You'll just be cloning it and editing it a bit.

Open the link here: https://glitch.com/edit/#!/shooter-arena-jwt

Click Remix To Edit to make it your own project. It should be at the top right corner.

Remix to Edit

Note: it is advisable you create a Glitch account, if not your project would be deleted after 5 days.

Go to index.js file and in function postRequest(id, success) change the hostname to your hasura backend url.

Hostname

You can get your hostname from your Hasura console.

url

Next up, go to the .env file to set your secrets.

SECRET=ADMIN_SECRET
CLIENT_TOKEN=CLIENT_TOKEN
PRIVATE_KEY=JWTSecretMustBeAtLeast32CharactersLong!

SECRET should be set to your Hasura admin secret CLIENT_TOKEN should be set to a phrase you want to use to authorize Unity. PRIVATE_KEY should be set to the HASURA_GRAPHQL_JWT_SECRET that's set for your Hasura Cloud project.

env

Next, rename your project.

Project name

Copy the live app link.

Live app

And let's head over to Unity.

Getting our JWT

Open your Unity project and create a new Api Reference. You can name it JWT

Paste the Glitch live app link you copied in the url slot and Introspect.

Introspect

Create a new query called GetJwt

GetJwt

And that's it. Calling this query with the right arguments will return a jwt for us to authenticate our Api calls with.

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