-
Notifications
You must be signed in to change notification settings - Fork 1
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
JWT Authentication option #6
Comments
Hello @NachoJusticia Let's first discuss about the inclusion of the JWT code. I would prefer to have them in separate files, not only because it will be more tidy and organized on the generated project, but also because it's easier to manage by the generator code. If most or all of the logic lives on separate files, all you have to do is to include or skip them based on a bolean. You have an example on the DockerFile inclusion: As you can see, if the user wants docker we copy the dockerfile, if the user does not want docker we do nothing. You can do the same for JWT if it lives on a separate plugin, which for me is also the preferred way to include stuff in a hapi server. About the code you have posted.... Why are you returning a promise for the registration ? Does hapi accept a promise instead of a callback ? Do you have any link to the documentation ? Thanks and regards Está bien que lo hayas puesto en inglés, esto es un proyecto open-source y así más gente puede entenderlo y participar. Un saludo |
Hi again @danielo515 and thank you for your answer. Regarding the JWT code, I thought in put this code in separate files as I showed you in my previous comment. But I think that even doing this I don't get how to achieve the problem that I have to include this plugin to the hapi server object and I guess I should do it in this file. I am returning a promise because I load a plugins module like this
This works fine. |
Hello @NachoJusticia
That is not how we register plugins on the generated project, we use glue. You are right about where to include the plugin registration, just add a conditional registration on the start.js file
|
Ok @danielo515 , then I will try to be consistent with the plugin registration like you suggest, I imagine this won't be a problem for me. Thank you! |
Hi @danielo515 After fixing some bugs that my code had, I am able to launch the server and get no errors. The problem is that I am able to see only 1 endpoint in the hapi-swagger documentation site (the vision endpoint). Maybe it is a problem related with Glue... Then, I would like you to have a look at my code and help me please! 👍 I'm registering the plugins like this:
In addition, I have created a simple DAO module and I decorate the server when init:
Well I think it's not a good idea to put more parts of my code here, it should be easier for you to have a look at my code directly. Thank! |
Just one question: healthcheck.js
version.js
|
Ok I have just noticed that I am missing this line:
in the plugins that are not available in the |
I have added 3 endpoints:
In the hapi-auth-jwt2 module they put a URL to a issue that they have with glue... https://www.npmjs.com/package/hapi-auth-jwt2 Then I have done what a user propose there, and it seems it works fine with glue now.
In the following image you can see that the endpoint /users/me doesn't allow to send the Authorization header, that is my problem... Now I post you an image of a similar backend (without Glue) that I have and in this case the /users/me endpoint works fine: As you can see when an user logins he receive a token in the Authorization header, but I have also included it in the object response because this way the developer will notice easier that he can handle this token. Anyhow you can tell me if putting the token just in the Authentication header is enough. Do you think I am missing something important here? |
Hello @NachoJusticia Thanks for your efforts. I have been checking your work and there are a couple of things that I want to check with you before we go any further. Most of them are style things.
Why is that split on three lines when it can fit on just one ? And, why are you duplicating that for both hapi-auth-jwt2 and jsonwebtoken ? EJS is weird and annoying enough, try to use as less of it's syntax as possible.
What's the reasoning behind that ? Why are you merging two lines that have nothing to do with each other ? Put the There are several other problems. Please branch your work, and go ahead with a pull request, review will be far easier there. Thanks and regards |
Hi @danielo515
is Anyhow you are right, I am checking the value of useAuthentication twice. Then I am going to write it as:
3.2. The reasoning behind that
is that I only want to get
when the user doesn't want authentication. Therefore, I put the , inside the if(useAuthentication). Anyhow I am going to write here the result of some of the files when I select that I want authentication:
package.json --> just the dependencies:
|
Hello again @NachoJusticia We should prefer template maintainability over beautiful code output. The main reason is that it can become very hard to maintain and read certain template structures while editing the final code can be trivial, and probably some linter will take care of it. So the following
can be written as
And no difference on the output should happen. Have you tried the output of your templates before changing them ? We should also agree on some EJS style-guides. For example, I always prefer Again, thanks for your time and keep up the good work. |
Hi @danielo515, Tell me if there anything else you want to change. |
As I said @NachoJusticia go ahead with the PR so we can better work together on the code. Thanks and regards |
@danielo515 I opened the PR 10 days ago |
Sorry @NachoJusticia I didn't noticed |
Then, I think we can close this issue and continue in the PR, do you agree? |
Hi, I would like to add JWT authentication because I think it would very interesting for this hapijs generator.
I have a hapijs backend in which I use the module hapi-auth-jwt2 and it is a plugin for the server object.
I have been able to:
but I don't know how to include the corresponding code of the authentication ONLY if the user has selected this option.
The code I would like to add is something like this:
Maybe I can put the plugin registration in an independent module like I show above, but another solution could be add it directly here:
default, development and test JSON files:
Could you please give me some guides about this problem?
Thanks :)
Perdona por el inglés, no sé porqué cuando me dí cuenta ya llevaba más de medio Pull Request 👍
The text was updated successfully, but these errors were encountered: