PassportAuthenticator
Index
Constructors
Properties
Methods
Constructors
constructor
Properties
_deserializers
_infoTransformers
_key
_serializers
applicationContext
passportConfig
Methods
publicaddDeserializer
publicaddInfoTransformer
publicaddSerializer
publicauthenticate
publicdeserializeUser
Registers a function used to deserialize user objects out of the session.
Examples:
passport.deserializeUser(function(id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
publicgetSessionUserProperty
publicgetUserProperty
publicisEnableSession
publicisExpressMode
publiclogInToSession
publiclogOutFromSession
publicserializeUser
publictransformAuthInfo
Registers a function used to transform auth info.
In some circumstances authorization details are contained in authentication credentials or loaded as part of verification.
For example, when using bearer tokens for API authentication, the tokens may encode (either directly or indirectly in a database), details such as scope of access or the client to which the token was issued.
Such authorization details should be enforced separately from authentication. Because Passport deals only with the latter, this is the responsiblity of middleware or routes further along the chain. However, it is not optimal to decode the same data or execute the same database query later. To avoid this, Passport accepts optional
info
along with the authenticateduser
in a strategy’ssuccess()
action. This info is set atreq.authInfo
, where said later middlware or routes can access it.Optionally, applications can register transforms to proccess this info, which take effect prior to
req.authInfo
being set. This is useful, for example, when the info contains a client ID. The transform can load the client from the database and include the instance in the transformed info, allowing the full set of client properties to be convieniently accessed.If no transforms are registered,
info
supplied by the strategy will be left unmodified.Examples:
passport.transformAuthInfo(function(info, done) {
Client.findById(info.clientID, function (err, client) {
info.client = client;
done(err, info);
});
});
Authenticates requests.
Applies the
name
ed strategy (or strategies) to the incoming request, in order to authenticate the request. If authentication is successful, the user will be logged in and populated atreq.user
and a session will be established by default. If authentication fails, an unauthorized response will be sent.Options:
session
Save login state in session, defaults to truesuccessRedirect
After successful login, redirect to given URLsuccessMessage
True to store success message in req.session.messages, or a string to use as override message for success.successFlash
True to flash success messages or a string to use as a flash message for success (overrides any from the strategy itself).failureRedirect
After failed login, redirect to given URLfailureMessage
True to store failure message in req.session.messages, or a string to use as override message for failure.failureFlash
True to flash failure messages or a string to use as a flash message for failures (overrides any from the strategy itself).assignProperty
Assign the object provided by the verify callback to given property