thiagobustamante / typescript-rest

This is a lightweight annotation-based expressjs extension for typescript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The boilerplate project is outdated and does not work well with the new version

evelyne24 opened this issue · comments

After your update, 2.2.0, if someone is using your boilerplate project, it will stop working because there is an incompatibility with typescript-rest-swagger and multiple authenticators. I've added the stack trace in this other bug #91. Can you please update the documentation with a relevant example on how to use the securityDefinitions in swagger.config.json and the Swagger UI with Bearer Authorization?

I have this in swagger.config.json:

"securityDefinitions": {
	"Bearer": {
		"type": "apiKey",
		"in": "header",
		"name": "Authorization"
	}
}

This produces the following Swagger UI authorization:

Screenshot 2019-06-18 at 10 01 43

However, when I try any request in Swagger UI, the Authorization Header is not added: curl -X GET "http://localhost:8080/users/1/accounts?includeExpired=true" -H "accept: application/json"

I then updated to 2.2.0 and tried to add Server.registerAuthenticator(new MyCustomTokenAuth(), 'MyAuth'); and on my controller, I use @Security('ROLE_USER', 'MyAuth') but it seems that typescript-rest-swagger refuses to generate the swagger file with the following error:

node_modules/typescript-rest-swagger/dist/metadata/controllerGenerator.js:93
            scopes: d.arguments[1] ? d.arguments[1].elements.map(function (e) { return e.text; }) : undefined                                                
TypeError: Cannot read property 'map' of undefined

Could you update your boilerplate example and the documentation to provide a clear example on how to achieve this? Thanks.

Done. I opened a PR to typescript-rest-boilerplate:

vrudikov/typescript-rest-boilerplate#10

Hi. I see the update but this doesn't answer the Swagger UI Authorization question. Does it work with the new version 2.2.0 or not yet? And if it's supposed to work, can you include an example? This is a very common use case. Also, there's a comment that the update is actually breaking.

Hi @evelyne24,

Yes, it works with version 2.2.0 (+), but you need the latest version of typescript-rest-swagger (1.0.3 at least).

I send a PR to typescript-rest-boilerplate showing an working example: vrudikov/typescript-rest-boilerplate#12

In that example, I added two authenticators. Both of them using jwt with the secret: some-jwt-secret