Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fastify integration #31

Closed
wants to merge 4 commits into from

Conversation

Ethan-Arrowood
Copy link

Adds an integration for Fastify. I'll be adding unit tests tomorrow. Ref fastify/fastify-jwt#10 fastify/fastify-jwt#8

@lgomez
Copy link

lgomez commented May 9, 2018

Is there anything we can do to get this accepted and merged?

@Ethan-Arrowood
Copy link
Author

I think this repo might not be very active haha

@cocojoe
Copy link
Member

cocojoe commented May 23, 2018

@Ethan-Arrowood thanks for the contribution, you mentioned some tests?

@Ethan-Arrowood
Copy link
Author

Hi @cocojoe Ahh yes I did; I'll push some updates soon.

@sandrinodimattia
Copy link
Member

Please also rebase your changes 👍

@cocojoe
Copy link
Member

cocojoe commented Jun 4, 2018

@Ethan-Arrowood any updates on this? Thx

@Ethan-Arrowood
Copy link
Author

Hi apologies for the delay I had an incredible busy week finishing up final assignments for Uni. I'll try to hash this out today.

@Ethan-Arrowood
Copy link
Author

Alright rebased and fixed some merge conflicts. Started working on tests. Not sure what I should be testing so I'm using the existing tests as a reference. I also don't think Fastify works in the supertest request() method so I gotta see what to do about that.

@degrammer
Copy link
Contributor

degrammer commented Jun 25, 2018

Hi @Ethan-Arrowood we really appreciate this work, I was reviewing the integration of your changes with a local fastify server, since I don't have any experience with fastify, can you help us to clarify the implementation details and add it as an example on our examples directory ?
With this code I'm always getting this message: only RS256 is supported

const fastify = require('fastify')();
const fastifyJwt = require('fastify-jwt');
const jwksRsa = require('jwks-rsa');

fastify.post('/signup', (request, reply) => {
  reply.jwtSign(request.body, function (err, token) {
    return reply.send(err || { 'token': token })
  })
})

// Run the server!
const start = async () => {
  try {
    fastify.register(fastifyJwt, { 
      secret: jwksRsa.fastifyJwtSecret({
        jwksUri: 'http:https://localhost/.well-known/jwks.json'
      }),
      algorithms: ['RS256']
    })
    await fastify.listen(9000)
    fastify.log.info(`server listening on ${fastify.server.address().port}`)
  } catch (err) {
    fastify.log.error(err)
    process.exit(1)
  }
}
start()

@Ethan-Arrowood
Copy link
Author

Will work on an example now.

@Ethan-Arrowood
Copy link
Author

Okay I'm unsure how to mock a jwks locally, but this code should work. It is pretty much what you sent just the register block is moved to outside the start method. I was using this in a project a while back with Auth0 as well as some scoping authz functionality. The project went stagnant about 4-5 months ago so i don't know how well its working anymore. If this demo still doesn't work I'll see what I can make happen from scratch.

Sorry I've been touch and go with this PR. I pushed it to the back of my mind a while back, so now I'm just trying to remember how to get it all working again.

@degrammer
Copy link
Contributor

Thank you @Ethan-Arrowood I will review it.

@vcanales
Copy link

vcanales commented Nov 23, 2018

Hi @Ethan-Arrowood we really appreciate this work, I was reviewing the integration of your changes with a local fastify server, since I don't have any experience with fastify, can you help us to clarify the implementation details and add it as an example on our examples directory ?
With this code I'm always getting this message: only RS256 is supported

Had the same issue, I had to add decode: { complete: true } to the options object to get the headers along with the payload of the token. This PR seems a bit stale, may I chime in with a working implementation? There's something else to consider in that the decode parameter is not returned if the token is invalid, so the "Only RS256 is supported" error is misleading in that case.

@vcanales
Copy link

@Ethan-Arrowood I've created a PR to your branch with suggested updates, I hope you have a chance to look at them. Also, please rebase this branch.

@Ethan-Arrowood
Copy link
Author

@vcanales I'll go through this tonight! Thank you

@Ethan-Arrowood
Copy link
Author

@vcanales looks like you made a pr to the master branch on my fork. Can you make your PR against the add-fastify branch on my fork instead please?

@Ethan-Arrowood
Copy link
Author

I have rebased my branch against origin master. Currently awaiting changes from @vcanales

@vcanales
Copy link

I have rebased my branch against origin master. Currently awaiting changes from @vcanales

Done! Sorry for the confusion :)

@vcanales
Copy link

vcanales commented Dec 3, 2018

Hello, @degrammer! I think we've addressed your concerns on previous comments with the latest changes. It would be amazing if you could take some time to re-review this!

@dnlup
Copy link

dnlup commented Mar 21, 2019

Are there any news on this? Can I help in any way?

@vcanales
Copy link

vcanales commented Jun 16, 2019

Gone off my own way and created a fork:

@stale
Copy link

stale bot commented Oct 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

@stale stale bot added the closed:stale Issue or PR has not seen activity recently label Oct 26, 2019
@stale stale bot closed this Nov 2, 2019
@tnguyen14
Copy link

Thanks @vcanales for the fork. Would've been great if this work was integrated into this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:stale Issue or PR has not seen activity recently
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants