1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/examples/basic-auth-hook.js
Fredrik Strand Oseberg c1aab06798
Feature/setup typescript
This sets up the typescript compiler.

Allowing gradual migration to typescript.

Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
Co-authored-by: Fredrik Oseberg <fredrik.oseberg@getunleash.ai>
Co-authored-by: Clint Checkett <clintchecketts@churchofjesuschrist.org>

fixes: #676
2021-02-12 11:42:00 +01:00

27 lines
720 B
JavaScript

/* eslint-disable import/no-unresolved */
'use strict';
const auth = require('basic-auth');
const { User } = require('../dist/lib/server-impl.js');
function basicAuthentication(app) {
app.use('/api/admin/', (req, res, next) => {
const credentials = auth(req);
if (credentials) {
// you will need to do some verification of credentials here.
const user = new User({ email: `${credentials.name}@domain.com` });
req.user = user;
return next();
}
return res
.status('401')
.set({ 'WWW-Authenticate': 'Basic realm="example"' })
.end('access denied');
});
}
module.exports = basicAuthentication;