From 3470a4ce606d9b4d620b6df0561b43913f481b8a Mon Sep 17 00:00:00 2001 From: Hugo Renard Date: Tue, 15 Feb 2022 16:26:52 +0100 Subject: [PATCH] auth select mode --- ScimApp.ts | 22 ++++++++++++++++------ src/endpoints/Context.ts | 14 ++++++++++---- src/endpoints/UserEndpoint.ts | 4 ---- src/endpoints/UsersEndpoint.ts | 4 ---- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ScimApp.ts b/ScimApp.ts index 1a6e329..ba4364f 100644 --- a/ScimApp.ts +++ b/ScimApp.ts @@ -1,7 +1,6 @@ import { IAppAccessors, IConfigurationExtend, - IConfigurationModify, ILogger, } from "@rocket.chat/apps-engine/definition/accessors"; import { @@ -10,16 +9,13 @@ import { } from "@rocket.chat/apps-engine/definition/api"; import { App } from "@rocket.chat/apps-engine/definition/App"; import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata"; -import { - ISetting, - SettingType, -} from "@rocket.chat/apps-engine/definition/settings"; +import { SettingType } from "@rocket.chat/apps-engine/definition/settings"; import { GroupEndpoint } from "./src/endpoints/GroupEndpoint"; import { GroupsEndpoint } from "./src/endpoints/GroupsEndpoint"; +import crypto = require("crypto"); import { UserEndpoint } from "./src/endpoints/UserEndpoint"; import { UsersEndpoint } from "./src/endpoints/UsersEndpoint"; -import crypto = require("crypto"); export class ScimApp extends App { constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { @@ -56,6 +52,20 @@ export class ScimApp extends App { 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({ id: "auth-bearer", type: SettingType.STRING, diff --git a/src/endpoints/Context.ts b/src/endpoints/Context.ts index bfddd2e..3e0a49b 100644 --- a/src/endpoints/Context.ts +++ b/src/endpoints/Context.ts @@ -55,12 +55,18 @@ export class Context { } public async checkAuth() { - const token = await this.read + const authMode = await this.read .getEnvironmentReader() .getSettings() - .getValueById("auth-bearer"); - if (this.request.headers.authorization !== `Bearer ${token}`) { - throw new UnauthorizedError(); + .getValueById("auth-mode"); + if (authMode === "bearer") { + const token = await this.read + .getEnvironmentReader() + .getSettings() + .getValueById("auth-bearer"); + if (this.request.headers.authorization !== `Bearer ${token}`) { + throw new UnauthorizedError(); + } } } } diff --git a/src/endpoints/UserEndpoint.ts b/src/endpoints/UserEndpoint.ts index b21e50f..6eaf6a9 100644 --- a/src/endpoints/UserEndpoint.ts +++ b/src/endpoints/UserEndpoint.ts @@ -1,9 +1,5 @@ import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; 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 { Context } from "./Context"; import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint"; diff --git a/src/endpoints/UsersEndpoint.ts b/src/endpoints/UsersEndpoint.ts index e2b1c79..e52cfd8 100644 --- a/src/endpoints/UsersEndpoint.ts +++ b/src/endpoints/UsersEndpoint.ts @@ -1,9 +1,5 @@ import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; -import { - RocketChatAssociationModel, - RocketChatAssociationRecord, -} from "@rocket.chat/apps-engine/definition/metadata"; import crypto = require("crypto"); import { SCIMListResponse } from "../scim/ListResponse"; import { SCIMUser } from "../scim/User";