mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
fix: configure user endpoint when AuthType is NONE (#1403)
Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
This commit is contained in:
parent
49f1a9f03e
commit
fc4d95ff5b
@ -1,16 +1,12 @@
|
|||||||
import { Application } from 'express';
|
import { Application } from 'express';
|
||||||
import { ADMIN } from '../types/permissions';
|
import NoAuthUser from '../types/no-auth-user';
|
||||||
import ApiUser from '../types/api-user';
|
|
||||||
|
|
||||||
function noneAuthentication(basePath = '', app: Application): void {
|
function noneAuthentication(basePath = '', app: Application): void {
|
||||||
app.use(`${basePath}/api/admin/`, (req, res, next) => {
|
app.use(`${basePath}/api/admin/`, (req, res, next) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
// @ts-ignore
|
// @ts-expect-error
|
||||||
req.user = new ApiUser({
|
req.user = new NoAuthUser();
|
||||||
username: 'unknown',
|
|
||||||
permissions: [ADMIN],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { IUnleashServices } from '../../types/services';
|
import { IUnleashServices } from '../../types/services';
|
||||||
import { IUnleashConfig } from '../../types/option';
|
import { IAuthType, IUnleashConfig } from '../../types/option';
|
||||||
import version from '../../util/version';
|
import version from '../../util/version';
|
||||||
|
|
||||||
import Controller from '../controller';
|
import Controller from '../controller';
|
||||||
@ -46,7 +46,9 @@ class ConfigController extends Controller {
|
|||||||
await this.settingService.get<SimpleAuthSettings>(simpleAuthKey);
|
await this.settingService.get<SimpleAuthSettings>(simpleAuthKey);
|
||||||
|
|
||||||
const versionInfo = this.versionService.getVersionInfo();
|
const versionInfo = this.versionService.getVersionInfo();
|
||||||
const disablePasswordAuth = simpleAuthSettings?.disabled;
|
const disablePasswordAuth =
|
||||||
|
simpleAuthSettings?.disabled ||
|
||||||
|
this.config.authentication.type == IAuthType.NONE;
|
||||||
res.json({ ...config, versionInfo, disablePasswordAuth });
|
res.json({ ...config, versionInfo, disablePasswordAuth });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ import { Response } from 'express';
|
|||||||
import { IAuthRequest } from '../unleash-types';
|
import { IAuthRequest } from '../unleash-types';
|
||||||
import Controller from '../controller';
|
import Controller from '../controller';
|
||||||
import { AccessService } from '../../services/access-service';
|
import { AccessService } from '../../services/access-service';
|
||||||
import { IUnleashConfig } from '../../types/option';
|
import { IAuthType, IUnleashConfig } from '../../types/option';
|
||||||
import { IUnleashServices } from '../../types/services';
|
import { IUnleashServices } from '../../types/services';
|
||||||
import UserService from '../../services/user-service';
|
import UserService from '../../services/user-service';
|
||||||
import SessionService from '../../services/session-service';
|
import SessionService from '../../services/session-service';
|
||||||
import UserFeedbackService from '../../services/user-feedback-service';
|
import UserFeedbackService from '../../services/user-feedback-service';
|
||||||
import UserSplashService from '../../services/user-splash-service';
|
import UserSplashService from '../../services/user-splash-service';
|
||||||
import { NONE } from '../../types/permissions';
|
import { ADMIN, NONE } from '../../types/permissions';
|
||||||
|
|
||||||
interface IChangeUserRequest {
|
interface IChangeUserRequest {
|
||||||
password: string;
|
password: string;
|
||||||
@ -58,9 +58,12 @@ class UserController extends Controller {
|
|||||||
async getUser(req: IAuthRequest, res: Response): Promise<void> {
|
async getUser(req: IAuthRequest, res: Response): Promise<void> {
|
||||||
res.setHeader('cache-control', 'no-store');
|
res.setHeader('cache-control', 'no-store');
|
||||||
const { user } = req;
|
const { user } = req;
|
||||||
const permissions = await this.accessService.getPermissionsForUser(
|
let permissions;
|
||||||
user,
|
if (this.config.authentication.type === IAuthType.NONE) {
|
||||||
);
|
permissions = [{ permission: ADMIN }];
|
||||||
|
} else {
|
||||||
|
permissions = await this.accessService.getPermissionsForUser(user);
|
||||||
|
}
|
||||||
const feedback = await this.userFeedbackService.getAllUserFeedback(
|
const feedback = await this.userFeedbackService.getAllUserFeedback(
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
|
22
src/lib/types/no-auth-user.ts
Normal file
22
src/lib/types/no-auth-user.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { ADMIN } from './permissions';
|
||||||
|
|
||||||
|
export default class NoAuthUser {
|
||||||
|
isAPI: boolean;
|
||||||
|
|
||||||
|
username: string;
|
||||||
|
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
permissions: string[];
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
username: string = 'unknown',
|
||||||
|
id: number = -1,
|
||||||
|
permissions: string[] = [ADMIN],
|
||||||
|
) {
|
||||||
|
this.isAPI = true;
|
||||||
|
this.username = username;
|
||||||
|
this.id = id;
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user