A bedrock module that adds website or REST API authentication to bedrock via passport.
- npm v3+
npm install bedrock-passport
const brPassport = require('bedrock-passport');
app.server.post('/resources/:resourceId',
brPassport.ensureAuthenticated,
(req, res, next) => {
// resourceId available with req.params.resourceId
// user account available with req.user.account
res.sendStatus(204);
});
For documentation on configuration, see config.js.
There are a number of ways a client may authenticate itself with the REST API. These methods include:
- Website session based on user and password and using cookies.
This method of authentication is useful for clients that are under your control and who you trust with your password to the service.
Attempt to authenticate a user using the specified strategy. If authentication
is successful, a bedrock-passport.authenticate
event is emitted with an
object with this format:
{
strategy,
options,
user
}
Once all event handlers have run, a promise resolves with {user}
data.
Attempt to authenticate a user using all configured strategies. For every
authentication method, authenticate
will be called. If more than
one authentication method is configured to run automatically, all of the
associated accounts must match.
Creates express middleware that calls authenticate
using the given strategy.
Express middleware that processes a request has been optionally authenticated
via authenticateAll
. Code using this call can check if the request is
authenticated by testing if req.user
and req.user.account
are set.
Express middleware that ensures a request has been authenticated via
optionallyAuthenticated
. Redirect if not and it looks like a browser GET
request, otherwise set a 400 error.