1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

fix: demo-auth should use /auth path

This commit is contained in:
Ivar Conradi Østhus 2021-10-26 23:04:44 +02:00
parent dc1df85dce
commit 131eeeaa78
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
8 changed files with 21 additions and 27 deletions

View File

@ -11,22 +11,16 @@ function demoAuthentication(
{ userService }: Pick<IUnleashServices, 'userService'>, { userService }: Pick<IUnleashServices, 'userService'>,
{ authentication }: Pick<IUnleashConfig, 'authentication'>, { authentication }: Pick<IUnleashConfig, 'authentication'>,
): void { ): void {
app.post(`${basePath}/api/admin/login`, async (req, res) => { app.post(`${basePath}/auth/demo/login`, async (req, res) => {
const { email } = req.body; const { email } = req.body;
try { try {
const user = await userService.loginUserWithoutPassword( const user = await userService.loginUserWithoutPassword(
email, email,
true, true,
); );
const session = req.session || {};
//@ts-ignore //@ts-ignore
session.user = user; req.session.user = user;
// @ts-ignore return res.status(200).json(user);
req.session = session;
res.status(200)
// @ts-ignore
.json(req.session.user)
.end();
} catch (e) { } catch (e) {
res.status(400) res.status(400)
.json({ error: `Could not sign in with ${email}` }) .json({ error: `Could not sign in with ${email}` })
@ -67,7 +61,7 @@ function demoAuthentication(
.status(401) .status(401)
.json( .json(
new AuthenticationRequired({ new AuthenticationRequired({
path: `${basePath}/api/admin/login`, path: `${basePath}/auth/demo/login`,
type: 'demo', type: 'demo',
message: message:
'You have to identify yourself in order to use Unleash.', 'You have to identify yourself in order to use Unleash.',

View File

@ -20,7 +20,7 @@ afterAll(async () => {
test('Should get ui-bootstrap data', async () => { test('Should get ui-bootstrap data', async () => {
// login // login
await app.request await app.request
.post('/api/admin/login') .post('/auth/demo/login')
.send({ .send({
email, email,
}) })

View File

@ -18,7 +18,7 @@ test('creates new feature toggle with createdBy', async () => {
const { request, destroy } = await setupAppWithAuth(db.stores); const { request, destroy } = await setupAppWithAuth(db.stores);
// Login // Login
await request.post('/api/admin/login').send({ await request.post('/auth/demo/login').send({
email: 'user@mail.com', email: 'user@mail.com',
}); });

View File

@ -26,7 +26,7 @@ test('should require authenticated user', async () => {
.status('401') .status('401')
.json( .json(
new AuthenticationRequired({ new AuthenticationRequired({
path: '/api/admin/login', path: '/auth/demo/login',
type: 'custom', type: 'custom',
message: 'You have to identify yourself.', message: 'You have to identify yourself.',
}), }),

View File

@ -20,7 +20,7 @@ afterAll(async () => {
test('Should get my user data', async () => { test('Should get my user data', async () => {
// login // login
await app.request await app.request
.post('/api/admin/login') .post('/auth/demo/login')
.send({ .send({
email, email,
}) })

View File

@ -172,7 +172,7 @@ test('Calling validate endpoint with already existing session should destroy ses
expect.assertions(0); expect.assertions(0);
const { request, destroy } = await setupAppWithAuth(stores); const { request, destroy } = await setupAppWithAuth(stores);
await request await request
.post('/api/admin/login') .post('/auth/demo/login')
.send({ .send({
email: 'user@mail.com', email: 'user@mail.com',
}) })
@ -206,7 +206,7 @@ test('Calling reset endpoint with already existing session should logout/destroy
token = res.body.token; token = res.body.token;
}); });
await request await request
.post('/api/admin/login') .post('/auth/demo/login')
.send({ .send({
email: 'user@mail.com', email: 'user@mail.com',
}) })

View File

@ -112,13 +112,13 @@ function googleAdminAuth(app) {
} }
``` ```
Implement a preRouter hook for `/api/admin/login`. It's necessary for login with Google. Implement a preRouter hook for `/auth/google/login`. It's necessary for login with Google.
```js ```js
function googleAdminAuth(app) { function googleAdminAuth(app) {
// ... // ...
app.get( app.get(
'/api/admin/login', '/auth/google/login',
passport.authenticate('google', { scope: ['email'] }), passport.authenticate('google', { scope: ['email'] }),
); );
// ... // ...
@ -158,7 +158,7 @@ function googleAdminAuth(app) {
.status('401') .status('401')
.json( .json(
new unleash.AuthenticationRequired({ new unleash.AuthenticationRequired({
path: '/api/admin/login', path: '/auth/google/login',
type: 'custom', type: 'custom',
message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`,
}), }),
@ -211,7 +211,7 @@ function googleAdminAuth(app) {
passport.deserializeUser((user, done) => done(null, user)); passport.deserializeUser((user, done) => done(null, user));
app.get( app.get(
'/api/admin/login', '/auth/google/login',
passport.authenticate('google', { scope: ['email'] }), passport.authenticate('google', { scope: ['email'] }),
); );
app.get( app.get(
@ -232,7 +232,7 @@ function googleAdminAuth(app) {
.status('401') .status('401')
.json( .json(
new unleash.AuthenticationRequired({ new unleash.AuthenticationRequired({
path: '/api/admin/login', path: '/auth/google/login',
type: 'custom', type: 'custom',
message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`,
}), }),

View File

@ -121,13 +121,13 @@ function googleAdminAuth(app, config, services) {
} }
``` ```
Implement a preRouter hook for `/api/admin/login`. It's necessary for login with Google. Implement a preRouter hook for `/auth/google/login`. It's necessary for login with Google.
```js ```js
function googleAdminAuth(app, config, services) { function googleAdminAuth(app, config, services) {
// ... // ...
app.get( app.get(
'/api/admin/login', '/auth/google/login',
passport.authenticate('google', { scope: ['email'] }), passport.authenticate('google', { scope: ['email'] }),
); );
// ... // ...
@ -167,7 +167,7 @@ function googleAdminAuth(app, config, services) {
.status('401') .status('401')
.json( .json(
new unleash.AuthenticationRequired({ new unleash.AuthenticationRequired({
path: '/api/admin/login', path: '/auth/google/login',
type: 'custom', type: 'custom',
message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`,
}), }),
@ -221,7 +221,7 @@ function googleAdminAuth(app, config, services) {
passport.deserializeUser((user, done) => done(null, user)); passport.deserializeUser((user, done) => done(null, user));
app.get( app.get(
'/api/admin/login', '/auth/google/login',
passport.authenticate('google', { scope: ['email'] }), passport.authenticate('google', { scope: ['email'] }),
); );
app.get( app.get(
@ -242,7 +242,7 @@ function googleAdminAuth(app, config, services) {
.status('401') .status('401')
.json( .json(
new unleash.AuthenticationRequired({ new unleash.AuthenticationRequired({
path: '/api/admin/login', path: '/auth/google/login',
type: 'custom', type: 'custom',
message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`, message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`,
}), }),