w3tecch / express-typescript-boilerplate

A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
MIT License
3.29k stars 904 forks source link

Authorize in http://localhost:3000/swagger #92

Closed zetekla closed 6 years ago

zetekla commented 6 years ago

How do I login so I can test/perform and verify all the REST endpoints?

What Value to enter in the form?

dweber019 commented 6 years ago

Hi @zetekla

First setup this repository with npm run setup

Then use this repo https://github.com/hirsch88/auth0-mock-server and get a token with https://github.com/hirsch88/auth0-mock-server#get-tokenusername for a user in the database (email).

Afterwards go to swagger and test.

zetekla commented 6 years ago

I have auth0-mock-server up and running. So, for the Value input in Swagger form, should I enter the Token I grabbed from auth0-mock-server ? How validation should work? I can't seem to get it to work.

Do I keep it AUTH_ROUTE=http://localhost:3333/tokeninfo ?

Should the username in mock-server be an email address in the boilerplate User's table after I run npm run setup ?

dweber019 commented 6 years ago

Yes the token has to be entered in Swagger right upper corner (Authorize) and there you enter "Bearer ".

The validation is done in https://github.com/w3tecch/express-typescript-boilerplate/blob/develop/src/auth/authorizationChecker.ts

Yes the auth0-mock-server has to be running and you need to keep AUTH_ROUTE.

Yes it should be the email address of the boilerplate. If you use the vanilla boilerplate then you can do bruce.wayne@wayne-enterprises.com.

zetekla commented 6 years ago

Yep. That works and this is how I went through: BUT the GET user/pet by ID, update by ID and Delete by Id doesn't work. Any hint?

Authorization with Swagger: 
1. auth0 server running localhost:3333/token/bruce.wayne@wayne-enterprises.com , to get the token
2. Login Swagger using `admin` and `1234`
3. then in Authorize enter `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiYXV0aDB8YnJ1Y2Uud2F5bmVAd2F5bmUtZW50ZXJwcmlzZXMuY29tIiwiaWF0IjoxNTI1NTYwMzE5fQ.4D5h6CeAu1RaW48uPTnG7ETRfdaWOFBSmyNbnjPC4tU`