auth select mode

This commit is contained in:
Hugo Renard 2022-02-15 16:26:52 +01:00
parent 67718df65d
commit 3470a4ce60
Signed by: hougo
GPG key ID: 3A285FD470209C59
4 changed files with 26 additions and 18 deletions

View file

@ -1,7 +1,6 @@
import { import {
IAppAccessors, IAppAccessors,
IConfigurationExtend, IConfigurationExtend,
IConfigurationModify,
ILogger, ILogger,
} from "@rocket.chat/apps-engine/definition/accessors"; } from "@rocket.chat/apps-engine/definition/accessors";
import { import {
@ -10,16 +9,13 @@ import {
} from "@rocket.chat/apps-engine/definition/api"; } from "@rocket.chat/apps-engine/definition/api";
import { App } from "@rocket.chat/apps-engine/definition/App"; import { App } from "@rocket.chat/apps-engine/definition/App";
import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata"; import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata";
import { import { SettingType } from "@rocket.chat/apps-engine/definition/settings";
ISetting,
SettingType,
} from "@rocket.chat/apps-engine/definition/settings";
import { GroupEndpoint } from "./src/endpoints/GroupEndpoint"; import { GroupEndpoint } from "./src/endpoints/GroupEndpoint";
import { GroupsEndpoint } from "./src/endpoints/GroupsEndpoint"; import { GroupsEndpoint } from "./src/endpoints/GroupsEndpoint";
import crypto = require("crypto");
import { UserEndpoint } from "./src/endpoints/UserEndpoint"; import { UserEndpoint } from "./src/endpoints/UserEndpoint";
import { UsersEndpoint } from "./src/endpoints/UsersEndpoint"; import { UsersEndpoint } from "./src/endpoints/UsersEndpoint";
import crypto = require("crypto");
export class ScimApp extends App { export class ScimApp extends App {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
@ -56,6 +52,20 @@ export class ScimApp extends App {
i18nLabel: "Rocket.Chat Token", i18nLabel: "Rocket.Chat Token",
}); });
configuration.settings.provideSetting({
id: "auth-mode",
type: SettingType.SELECT,
packageValue: "",
required: true,
public: false,
i18nLabel: "Auth mode for the SCIM endpoints.",
value: "bearer",
values: [
{ key: "bearer", i18nLabel: "Bearer token" },
{ key: "none", i18nLabel: "None" },
],
});
configuration.settings.provideSetting({ configuration.settings.provideSetting({
id: "auth-bearer", id: "auth-bearer",
type: SettingType.STRING, type: SettingType.STRING,

View file

@ -55,12 +55,18 @@ export class Context {
} }
public async checkAuth() { public async checkAuth() {
const token = await this.read const authMode = await this.read
.getEnvironmentReader() .getEnvironmentReader()
.getSettings() .getSettings()
.getValueById("auth-bearer"); .getValueById("auth-mode");
if (this.request.headers.authorization !== `Bearer ${token}`) { if (authMode === "bearer") {
throw new UnauthorizedError(); const token = await this.read
.getEnvironmentReader()
.getSettings()
.getValueById("auth-bearer");
if (this.request.headers.authorization !== `Bearer ${token}`) {
throw new UnauthorizedError();
}
} }
} }
} }

View file

@ -1,9 +1,5 @@
import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors";
import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; import { IApiResponse } from "@rocket.chat/apps-engine/definition/api";
import {
RocketChatAssociationModel,
RocketChatAssociationRecord,
} from "@rocket.chat/apps-engine/definition/metadata";
import { SCIMUser } from "../scim/User"; import { SCIMUser } from "../scim/User";
import { Context } from "./Context"; import { Context } from "./Context";
import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint"; import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint";

View file

@ -1,9 +1,5 @@
import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors";
import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; import { IApiResponse } from "@rocket.chat/apps-engine/definition/api";
import {
RocketChatAssociationModel,
RocketChatAssociationRecord,
} from "@rocket.chat/apps-engine/definition/metadata";
import crypto = require("crypto"); import crypto = require("crypto");
import { SCIMListResponse } from "../scim/ListResponse"; import { SCIMListResponse } from "../scim/ListResponse";
import { SCIMUser } from "../scim/User"; import { SCIMUser } from "../scim/User";