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 {
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,

View file

@ -55,6 +55,11 @@ export class Context {
}
public async checkAuth() {
const authMode = await this.read
.getEnvironmentReader()
.getSettings()
.getValueById("auth-mode");
if (authMode === "bearer") {
const token = await this.read
.getEnvironmentReader()
.getSettings()
@ -63,4 +68,5 @@ export class Context {
throw new UnauthorizedError();
}
}
}
}

View file

@ -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";

View file

@ -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";