snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 1s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 1s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
This commit is contained in:
296
apps/meteor/server/api/v1/oauthapps.ts
Normal file
296
apps/meteor/server/api/v1/oauthapps.ts
Normal file
@@ -0,0 +1,296 @@
|
||||
import type { IOAuthApps } from '@rocket.chat/core-typings';
|
||||
import { OAuthApps } from '@rocket.chat/models';
|
||||
import {
|
||||
ajv,
|
||||
ajvQuery,
|
||||
validateUnauthorizedErrorResponse,
|
||||
validateBadRequestErrorResponse,
|
||||
validateForbiddenErrorResponse,
|
||||
} from '@rocket.chat/rest-typings';
|
||||
|
||||
import { addOAuthApp } from '../../lib/auth/oauth2-server/addOAuthApp';
|
||||
import { hasPermissionAsync } from '../../lib/authorization/hasPermission';
|
||||
import { deleteOAuthApp } from '../../meteor-methods/auth/deleteOAuthApp';
|
||||
import { updateOAuthApp } from '../../meteor-methods/auth/updateOAuthApp';
|
||||
import type { ExtractRoutesFromAPI } from '../ApiClass';
|
||||
import { API } from '../api';
|
||||
|
||||
type DeleteOAuthAppParams = {
|
||||
appId: string;
|
||||
};
|
||||
|
||||
const DeleteOAuthAppParamsSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
appId: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['appId'],
|
||||
additionalProperties: false,
|
||||
};
|
||||
|
||||
const isDeleteOAuthAppParams = ajv.compile<DeleteOAuthAppParams>(DeleteOAuthAppParamsSchema);
|
||||
|
||||
export type OauthAppsAddParams = {
|
||||
name: string;
|
||||
active: boolean;
|
||||
redirectUri: string;
|
||||
};
|
||||
|
||||
const OauthAppsAddParamsSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
active: {
|
||||
type: 'boolean',
|
||||
},
|
||||
redirectUri: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['name', 'active', 'redirectUri'],
|
||||
additionalProperties: false,
|
||||
};
|
||||
|
||||
const isOauthAppsAddParams = ajv.compile<OauthAppsAddParams>(OauthAppsAddParamsSchema);
|
||||
|
||||
type UpdateOAuthAppParams = {
|
||||
appId: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
clientId?: string | undefined;
|
||||
clientSecret?: string | undefined;
|
||||
redirectUri: string;
|
||||
};
|
||||
|
||||
const UpdateOAuthAppParamsSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
appId: {
|
||||
type: 'string',
|
||||
},
|
||||
name: {
|
||||
type: 'string',
|
||||
},
|
||||
active: {
|
||||
type: 'boolean',
|
||||
},
|
||||
redirectUri: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['appId', 'name', 'active', 'redirectUri'],
|
||||
additionalProperties: false,
|
||||
};
|
||||
|
||||
const isUpdateOAuthAppParams = ajv.compile<UpdateOAuthAppParams>(UpdateOAuthAppParamsSchema);
|
||||
|
||||
type OauthAppsGetParams = { clientId: string } | { _id: string };
|
||||
|
||||
const oauthAppsGetParamsSchema = {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
_id: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['_id'],
|
||||
additionalProperties: false,
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
clientId: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['clientId'],
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const isOauthAppsGetParams = ajvQuery.compile<OauthAppsGetParams>(oauthAppsGetParamsSchema);
|
||||
|
||||
const oauthAppsEndpoints = API.v1
|
||||
.get(
|
||||
'oauth-apps.list',
|
||||
{
|
||||
authRequired: true,
|
||||
query: ajvQuery.compile<{ uid?: string }>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
uid: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
}),
|
||||
permissionsRequired: ['manage-oauth-apps'],
|
||||
response: {
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
200: ajv.compile<{ oauthApps: IOAuthApps[] }>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
oauthApps: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: '#/components/schemas/IOAuthApps',
|
||||
},
|
||||
},
|
||||
success: {
|
||||
type: 'boolean',
|
||||
enum: [true],
|
||||
},
|
||||
},
|
||||
required: ['oauthApps', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
async function action() {
|
||||
return API.v1.success({
|
||||
oauthApps: await OAuthApps.find().toArray(),
|
||||
});
|
||||
},
|
||||
)
|
||||
.post(
|
||||
'oauth-apps.delete',
|
||||
{
|
||||
authRequired: true,
|
||||
body: isDeleteOAuthAppParams,
|
||||
permissionsRequired: ['manage-oauth-apps'],
|
||||
response: {
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
200: ajv.compile<boolean>({ type: 'boolean' }),
|
||||
},
|
||||
},
|
||||
|
||||
async function action() {
|
||||
const { appId } = this.bodyParams;
|
||||
|
||||
const result = await deleteOAuthApp(this.userId, appId);
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
)
|
||||
.post(
|
||||
'oauth-apps.create',
|
||||
{
|
||||
authRequired: true,
|
||||
body: isOauthAppsAddParams,
|
||||
permissionsRequired: ['manage-oauth-apps'],
|
||||
response: {
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
200: ajv.compile<{ application: IOAuthApps }>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
application: { $ref: '#/components/schemas/IOAuthApps' },
|
||||
success: {
|
||||
type: 'boolean',
|
||||
enum: [true],
|
||||
},
|
||||
},
|
||||
required: ['application', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
async function action() {
|
||||
const application = await addOAuthApp(this.bodyParams, this.userId);
|
||||
|
||||
return API.v1.success({ application });
|
||||
},
|
||||
)
|
||||
.post(
|
||||
'oauth-apps.update',
|
||||
{
|
||||
authRequired: true,
|
||||
body: isUpdateOAuthAppParams,
|
||||
permissionsRequired: ['manage-oauth-apps'],
|
||||
response: {
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
200: ajv.compile<IOAuthApps | null>({
|
||||
allOf: [
|
||||
{ anyOf: [{ $ref: '#/components/schemas/IOAuthApps' }, { type: 'null' }] },
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean', enum: [true] },
|
||||
},
|
||||
required: ['success'],
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const { appId } = this.bodyParams;
|
||||
|
||||
const result = await updateOAuthApp(this.userId, appId, this.bodyParams);
|
||||
|
||||
return API.v1.success(result);
|
||||
},
|
||||
)
|
||||
.get(
|
||||
'oauth-apps.get',
|
||||
{
|
||||
authRequired: true,
|
||||
query: isOauthAppsGetParams,
|
||||
response: {
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
200: ajv.compile<{ oauthApp: IOAuthApps }>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
oauthApp: { anyOf: [{ $ref: '#/components/schemas/IOAuthApps' }, { type: 'null' }] },
|
||||
success: {
|
||||
type: 'boolean',
|
||||
enum: [true],
|
||||
},
|
||||
},
|
||||
required: ['oauthApp', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
async function action() {
|
||||
const isOAuthAppsManager = await hasPermissionAsync(this.user, 'manage-oauth-apps');
|
||||
|
||||
const oauthApp = await OAuthApps.findOneAuthAppByIdOrClientId(
|
||||
this.queryParams,
|
||||
!isOAuthAppsManager ? { projection: { clientSecret: 0 } } : {},
|
||||
);
|
||||
|
||||
if (!oauthApp) {
|
||||
return API.v1.failure('OAuth app not found.');
|
||||
}
|
||||
|
||||
return API.v1.success({
|
||||
oauthApp,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
export type OauthAppsEndpoints = ExtractRoutesFromAPI<typeof oauthAppsEndpoints>;
|
||||
|
||||
declare module '@rocket.chat/rest-typings' {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
|
||||
interface Endpoints extends OauthAppsEndpoints {}
|
||||
}
|
||||
Reference in New Issue
Block a user