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

View File

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

View File

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

View File

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

View File

@ -172,7 +172,7 @@ test('Calling validate endpoint with already existing session should destroy ses
expect.assertions(0);
const { request, destroy } = await setupAppWithAuth(stores);
await request
.post('/api/admin/login')
.post('/auth/demo/login')
.send({
email: 'user@mail.com',
})
@ -206,7 +206,7 @@ test('Calling reset endpoint with already existing session should logout/destroy
token = res.body.token;
});
await request
.post('/api/admin/login')
.post('/auth/demo/login')
.send({
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
function googleAdminAuth(app) {
// ...
app.get(
'/api/admin/login',
'/auth/google/login',
passport.authenticate('google', { scope: ['email'] }),
);
// ...
@ -158,7 +158,7 @@ function googleAdminAuth(app) {
.status('401')
.json(
new unleash.AuthenticationRequired({
path: '/api/admin/login',
path: '/auth/google/login',
type: 'custom',
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));
app.get(
'/api/admin/login',
'/auth/google/login',
passport.authenticate('google', { scope: ['email'] }),
);
app.get(
@ -232,7 +232,7 @@ function googleAdminAuth(app) {
.status('401')
.json(
new unleash.AuthenticationRequired({
path: '/api/admin/login',
path: '/auth/google/login',
type: 'custom',
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
function googleAdminAuth(app, config, services) {
// ...
app.get(
'/api/admin/login',
'/auth/google/login',
passport.authenticate('google', { scope: ['email'] }),
);
// ...
@ -167,7 +167,7 @@ function googleAdminAuth(app, config, services) {
.status('401')
.json(
new unleash.AuthenticationRequired({
path: '/api/admin/login',
path: '/auth/google/login',
type: 'custom',
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));
app.get(
'/api/admin/login',
'/auth/google/login',
passport.authenticate('google', { scope: ['email'] }),
);
app.get(
@ -242,7 +242,7 @@ function googleAdminAuth(app, config, services) {
.status('401')
.json(
new unleash.AuthenticationRequired({
path: '/api/admin/login',
path: '/auth/google/login',
type: 'custom',
message: `You have to identify yourself in order to use Unleash. Click the button and follow the instructions.`,
}),