• Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login
FusionAuth
  • Home
  • Categories
  • Recent
  • Popular
  • Pricing
  • Contact us
  • Docs
  • Login

FusionAuth / Fastify

Scheduled Pinned Locked Moved Unsolved
Q&A
2
2
504
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    mark 0
    last edited by 25 Aug 2022, 18:58

    Does anyone have their (node) api service protected by FusionAuth using fastify? I have a simple POC that works with auth0 and the api is protected fairly easily with the below code:

    // get variables from environment / enable auth0
    fastify.register(require('fastify-auth0-verify'), {
      domain: process.env.AUTH0_DOMAIN,
      secret: process.env.AUTH0_SECRET
    });
    // Actually turns on auth0
    fastify.addHook("onRequest", async (request, reply) => {
      try {
        await request.jwtVerify()
      } catch (err) {
        reply.send(err)
      }
    });
    

    With the above code I can fairly easily grab the bearer token and pass that into curl (curl -H "Authorization: Bearer ${TOKEN}" ${SRV}/apiV1/users) for both production/testing purposes. If the bearer token is not valid it fails at the request level.

    We're not that far along that I couldn't recode this into express to test the differences between the systems, but as it's working with fastify...

    D 1 Reply Last reply 27 Aug 2022, 11:37 Reply Quote 1
    • D
      dan @mark 0
      last edited by 27 Aug 2022, 11:37

      @mark-0

      I have not done this, but from looking at the Fastify JWT library, it looks pretty straight forward:

      https://github.com/fastify/fastify-jwt#options

      Since there's no Fastify FusionAuth integration, you need to pass the public and private key if you want to verify and sign the JWTs, respectively. Since FusionAuth is creating the JWT, in theory you could just pass the public key of an RSA keypair, since you'll never need to sign the JWT (haven't tested that though).

      To add the keys to FusionAuth, you'll want to use Keymaster: https://fusionauth.io/docs/v1/tech/core-concepts/key-master

      Hope that helps.

      --
      FusionAuth - Auth for devs, built by devs.
      https://fusionauth.io

      1 Reply Last reply Reply Quote 0
      1 out of 2
      • First post
        1/2
        Last post