The middleware parameters.
An Express middleware accepting server.AuthenticateRequestParameters parameters.
const fief = require('@fief/fief');
const fiefExpress = require('@fief/fief/express');
const express = require('express');
const fiefClient = new fief.Fief({
baseURL: 'https://example.fief.dev',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
});
const fiefAuthMiddleware = fiefExpress.createMiddleware({
client: fiefClient,
tokenGetter: fiefExpress.authorizationSchemeGetter(),
});
const app = express();
app.get('/authenticated', fiefAuthMiddleware(), (req, res) => {
res.json(req.accessTokenInfo);
});
app.get(
'/authenticated-scope',
fiefAuthMiddleware({ scope: ['required_scope'] }),
(req, res) => {
res.json(req.accessTokenInfo);
},
);
app.get(
'/authenticated-acr',
fiefAuthMiddleware({ acr: FiefACR.LEVEL_ONE }),
(req, res) => {
res.json(req.accessTokenInfo);
},
);
app.get(
'/authenticated-permission',
fiefAuthMiddleware({ permissions: ['castles:create'] }),
(req, res) => {
res.json(req.accessTokenInfo);
},
);
Return an Express authentication middleware.