- Passport is the most widely used authentication module
for Node.js.
You'll find it at passportjs.org and on GitHub.
Conceptually, Passport provides an authenticate function.
This function uses a so-called strategy
to authenticate the user.
There are over 500 strategies available.
Strategies are plugable authentication modules
that can be installed separately.
Through these strategies,
Passport covers a variety of backends or use cases
from local authentication that
is mostly used to authenticate against the local database,
to strategies for many third party systems.
including things and non-providers
and log-ins for social media accounts like,
Facebook or GitHub,
or even rather exotic systems like Shibboleth.
Once a user successfully authenticated passport
also takes care of things like storing the user
in the session and also restoring it
for every request.
To use passport in express,
it needs to be hooked into the application
with two middleware functions.
What do these two middle ware functions do?
The first function is passport initialize,
and it provides a middleware function that uses
the request object to store passport internal data in it.
The second function is passport session.
This middleware basically looks into the session
and if there is user data in this session.
It will use this data to decentralize the user.
For instance, you can store the user ID with
the session and decentralize function built in.
Fetch the user with this user ID from the database,
and then it will provide this user
and the request that user
to all following middleware and droughts.
In the next videos, we're going to add passport
to a playground application,
and start using it for authentication.