moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 118 forks source link

Authorization #209

Closed pontarolli closed 3 years ago

pontarolli commented 3 years ago

Hello guys !!!

I'm trying to use the auth.service.js from the api gateway using the full example. https://github.com/moleculerjs/moleculer-web/blob/master/examples/auth.service.js https://github.com/moleculerjs/moleculer-web/tree/master/examples/full.

When trying to access: https://localhost:4000/api/admin/~node/health Route error: Not found

https://github.com/moleculerjs/moleculer-web/blob/f4669daaede6ec55e29e32bd6f32c957e58614e9/examples/full/index.js#L141 Soon I noticed in the aliases “health”: “$node.health”, so I accessed it in another way to have a valid return. https://localhost:4000/api/admin/health Route error: Unauthorized

I generated a token for the admin user: https://localhost:4000/api/login?username=admin&password=admin {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwicm9sZSI6ImFkbWluIiwiaWF0IjoxNjAwOTY4NjU5fQ.aA3R5vu8TqP9EZOFr0r7YnD32xYWAlCgWZ3unaeWS10"}

I tried to access again, but now with the token in the header following the pattern Authorization: type token https://localhost:4000/api/admin/health

https://github.com/moleculerjs/moleculer-web/blob/f4669daaede6ec55e29e32bd6f32c957e58614e9/examples/full/index.js#L357-L359

Authorization: Token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwicm9sZSI6ImFkbWluIiwiaWF0IjoxNjAwOTY4NjU5fQ.aA3R5vu8TqP9EZOFr0r7YnD32xYWAlCgWZ3unaeWS10 Route error: Unauthorized

If you disable authorization, false, I get the desired return. https://github.com/moleculerjs/moleculer-web/blob/f4669daaede6ec55e29e32bd6f32c957e58614e9/examples/full/index.js#L134

However I would like to use the authentication / authorization mechanism as I will have several users accessing the api gateway.

icebob commented 3 years ago

The full example has been fixed.

pontarolli commented 3 years ago

Now it worked perfectly. Thank you very much for the quick solution ninja icebob.