johnbrett / hapi-auth-bearer-token

Simple Bearer authentication scheme plugin for hapi, accepts token by Header, Cookie or Query parameter.
MIT License
218 stars 46 forks source link

Pass auth artifacts to Hapi. #76

Closed koresar closed 8 years ago

koresar commented 8 years ago

This enables Hapi auth artifacts. Quoting hapijs.com:

Additionally, you may also have an artifacts key, which can contain any authentication related data that is not part of the user's credentials.

And this:

artifacts - an optional artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly as if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.

johnbrett commented 8 years ago

Hi @koresar, thanks for this PR! Planning on getting to this tonight FYI - but it looks good. Thanks for linking to the relevant API docs.

Curious about this, what type of stuff do you use this for?

koresar commented 8 years ago

@johnbrett Thanks for spending time on this.

When a microservice S1 receives a HTTP call it calls a different "auth microservice" S2 to validate the received token. In addition to authentication the S2 also returns user data (aka user entity) to minimize the number of the DB calls. The S1 would need that user entity regardless.

In other words, we read user entity from DB once and then share it via the artifacts so that S1 don't need to reread the entity.

koresar commented 8 years ago

Thank you very much @johnbrett ! Looking forward to npm install it. Cheers :)

johnbrett commented 8 years ago

Merged - thanks for the PR @koresar! Microservices with hapi sounds really interesting! is it open source? if not would love a blog post or anything on it! :)

koresar commented 8 years ago

@johnbrett it's all private code unfortunately. We, the SafetyCulture, are going to create development blog and opensource various NPM modules this year.

johnbrett commented 8 years ago

That's really cool man, best of luck with that! By the way I practice OPEN open source on my projects where possible: http://openopensource.org/, would you like commit access to this repo? :)

koresar commented 8 years ago

LOL. Me too. :) https://github.com/koresar/fcql#want-to-contribute

Yeah. Commit access would be great. :)

johnbrett commented 8 years ago

Done - and makes it all the more awesome to give commit access to someone who also does open open source :)