Skip to content

Commit b18885c

Browse files
committed
WIP
1 parent e12d402 commit b18885c

9 files changed

Lines changed: 44 additions & 86 deletions

File tree

packages/react-ui/src/app/routes/cloud-connection/cloud-connection-page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,14 @@ const CloudConnectionPage = () => {
3333
if (!flags || isLoading) {
3434
return;
3535
}
36-
const { FRONTEGG_URL, FRONTEGG_CLIENT_ID, FRONTEGG_APP_ID } = flags;
36+
const { FRONTEGG_URL } = flags;
3737

38-
if (!FRONTEGG_URL || !FRONTEGG_CLIENT_ID || !FRONTEGG_APP_ID) {
38+
if (!FRONTEGG_URL) {
3939
navigate('/');
4040
return;
4141
}
4242

43-
const app = initializeFrontegg(
44-
FRONTEGG_URL as string,
45-
FRONTEGG_CLIENT_ID as string,
46-
FRONTEGG_APP_ID as string,
47-
);
43+
const app = initializeFrontegg(FRONTEGG_URL as string);
4844

4945
app.ready(() => {
5046
app.store.subscribe(() => {

packages/react-ui/src/app/routes/cloud-connection/cloud-logout-page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,14 @@ const CloudLogoutPage = () => {
3030
if (!flags || isLoading) {
3131
return;
3232
}
33-
const { FRONTEGG_URL, FRONTEGG_CLIENT_ID, FRONTEGG_APP_ID } = flags;
33+
const { FRONTEGG_URL } = flags;
3434

35-
if (!FRONTEGG_URL || !FRONTEGG_CLIENT_ID || !FRONTEGG_APP_ID) {
35+
if (!FRONTEGG_URL) {
3636
navigate('/');
3737
return;
3838
}
3939

40-
const app = initializeFrontegg(
41-
FRONTEGG_URL as string,
42-
FRONTEGG_CLIENT_ID as string,
43-
FRONTEGG_APP_ID as string,
44-
);
40+
const app = initializeFrontegg(FRONTEGG_URL as string);
4541

4642
Cookies.remove('cloud-token');
4743
Cookies.remove('cloud-refresh-token');
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import { initialize } from '@frontegg/js';
1+
import { FronteggApp, initialize } from '@frontegg/js';
22

33
export const additionalFronteggParams = {
44
// Google OAuth 2.0: Prompt the user to select an account. https://developers.google.com/identity/protocols/oauth2/web-server#creatingclient
55
prompt: 'select_account',
66
};
77

8-
export const initializeFrontegg = (
9-
FRONTEGG_URL: string,
10-
FRONTEGG_CLIENT_ID: string,
11-
FRONTEGG_APP_ID: string,
12-
) =>
13-
initialize({
8+
export function initializeFrontegg(url: string, tenant?: string): FronteggApp {
9+
const tenantResolver = tenant ? () => ({ tenant: tenant }) : undefined;
10+
11+
return initialize({
1412
contextOptions: {
15-
baseUrl: FRONTEGG_URL as string,
16-
clientId: FRONTEGG_CLIENT_ID as string,
17-
appId: FRONTEGG_APP_ID as string,
13+
baseUrl: url,
14+
tenantResolver,
1815
},
1916
authOptions: {
2017
keepSessionAlive: true,
2118
},
2219
hostedLoginBox: true,
2320
});
21+
}

packages/server/api/src/app/flags/flag.service.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,6 @@ export const flagService = {
251251
created,
252252
updated,
253253
},
254-
{
255-
id: FlagId.FRONTEGG_CLIENT_ID,
256-
value: system.get(AppSystemProp.FRONTEGG_CLIENT_ID),
257-
created,
258-
updated,
259-
},
260-
{
261-
id: FlagId.FRONTEGG_APP_ID,
262-
value: system.get(AppSystemProp.FRONTEGG_APP_ID),
263-
created,
264-
updated,
265-
},
266254
{
267255
id: FlagId.CLOUD_CONNECTION_PAGE_ENABLED,
268256
value: system.getBoolean(AppSystemProp.CLOUD_CONNECTION_PAGE_ENABLED),

packages/server/api/src/app/flow-template/cloud-template.controller.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,26 @@ import {
22
FastifyPluginAsyncTypebox,
33
Type,
44
} from '@fastify/type-provider-typebox';
5-
import { IdentityClient } from '@frontegg/client';
65
import { AppSystemProp, logger, system } from '@openops/server-shared';
76
import { ALL_PRINCIPAL_TYPES, OpenOpsId } from '@openops/shared';
8-
import { getCloudToken, getCloudUser } from '../user-info/cloud-auth';
7+
import { getVerifiedUser } from '../user-info/cloud-auth';
98
import { flowTemplateService } from './flow-template.service';
109

1110
export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
1211
app,
1312
) => {
14-
const fronteggClientId = system.get(AppSystemProp.FRONTEGG_CLIENT_ID);
15-
const fronteggApiKey = system.get(AppSystemProp.FRONTEGG_API_KEY);
13+
const publicKey = system.get(AppSystemProp.FRONTEGG_PUBLIC_KEY);
14+
const connectionPageEnabled = system.getBoolean(
15+
AppSystemProp.CLOUD_CONNECTION_PAGE_ENABLED,
16+
);
1617

17-
if (!fronteggClientId || !fronteggApiKey) {
18+
if (!publicKey || !connectionPageEnabled) {
1819
logger.info(
1920
'Missing Frontegg configuration, disabling cloud templates API',
2021
);
2122
return;
2223
}
2324

24-
const identityClient = new IdentityClient({
25-
FRONTEGG_CLIENT_ID: fronteggClientId,
26-
FRONTEGG_API_KEY: fronteggApiKey,
27-
});
28-
2925
// cloud templates are available on any origin
3026
app.addHook('onSend', (request, reply, payload, done) => {
3127
void reply.header(
@@ -38,7 +34,6 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
3834
'Content-Type,Ops-Origin,Authorization',
3935
);
4036
void reply.header('Access-Control-Allow-Credentials', 'true');
41-
4237
if (request.method === 'OPTIONS') {
4338
return reply.status(204).send();
4439
}
@@ -70,9 +65,8 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
7065
},
7166
},
7267
async (request) => {
73-
const token = getCloudToken(request);
74-
75-
if (!(await getCloudUser(identityClient, token))) {
68+
const user = getVerifiedUser(request, publicKey);
69+
if (!user) {
7670
return flowTemplateService.getFlowTemplates({
7771
search: request.query.search,
7872
tags: request.query.tags,
@@ -120,8 +114,9 @@ export const cloudTemplateController: FastifyPluginAsyncTypebox = async (
120114
},
121115
},
122116
async (request, reply) => {
123-
const token = getCloudToken(request);
124-
if (!(await getCloudUser(identityClient, token))) {
117+
const user = getVerifiedUser(request, publicKey);
118+
119+
if (!user) {
125120
const template = await flowTemplateService.getFlowTemplate(
126121
request.params.id,
127122
);
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
import { IdentityClient } from '@frontegg/client';
2-
import {
3-
IAccessToken,
4-
IEntityWithRoles,
5-
} from '@frontegg/client/dist/src/clients/identity/types';
61
import { FastifyRequest } from 'fastify';
2+
import jwt, { JwtPayload } from 'jsonwebtoken';
73

84
const CLOUD_TOKEN_COOKIE_NAME = 'cloud-token';
95

10-
export const getCloudToken = (request: FastifyRequest): string | undefined => {
6+
const getCloudToken = (request: FastifyRequest): string | undefined => {
117
let token = request.headers.authorization?.replace('Bearer ', '');
128
if (!token) {
139
token = request.cookies[CLOUD_TOKEN_COOKIE_NAME];
1410
}
1511
return token;
1612
};
1713

18-
export async function getCloudUser(
19-
identityClient: IdentityClient,
20-
token?: string,
21-
): Promise<null | IEntityWithRoles | IAccessToken> {
14+
export function getVerifiedUser(
15+
request: FastifyRequest,
16+
publicKey: string,
17+
): string | JwtPayload | undefined {
18+
const token = getCloudToken(request);
2219
if (!token) {
23-
return null;
20+
return undefined;
2421
}
2522

2623
try {
27-
const user = await identityClient.validateIdentityOnToken(token);
28-
return user;
29-
} catch (e) {
30-
// eslint-disable-next-line no-console
31-
console.error(e);
32-
return null;
24+
return jwt.verify(token, publicKey);
25+
} catch {
26+
return undefined;
3327
}
3428
}

packages/server/api/src/app/user-info/user-info.module.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox';
2-
import { IdentityClient } from '@frontegg/client';
32
import { AppSystemProp, logger, system } from '@openops/server-shared';
43
import { ALL_PRINCIPAL_TYPES } from '@openops/shared';
5-
import { getCloudToken, getCloudUser } from './cloud-auth';
4+
import { getVerifiedUser } from './cloud-auth';
65

76
export const userInfoModule: FastifyPluginAsyncTypebox = async (app) => {
87
await app.register(userInfoController, { prefix: '/v1/user-info' });
98
};
109

1110
export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
12-
const fronteggClientId = system.get(AppSystemProp.FRONTEGG_CLIENT_ID);
13-
const fronteggApiKey = system.get(AppSystemProp.FRONTEGG_API_KEY);
11+
const publicKey = system.get(AppSystemProp.FRONTEGG_PUBLIC_KEY);
12+
const connectionPageEnabled = system.getBoolean(
13+
AppSystemProp.CLOUD_CONNECTION_PAGE_ENABLED,
14+
);
1415

15-
if (!fronteggClientId || !fronteggApiKey) {
16+
if (!publicKey || !connectionPageEnabled) {
1617
logger.info(
1718
'Missing Frontegg configuration, disabling cloud templates API',
1819
);
1920
return;
2021
}
2122

22-
const identityClient = new IdentityClient({
23-
FRONTEGG_CLIENT_ID: fronteggClientId,
24-
FRONTEGG_API_KEY: fronteggApiKey,
25-
});
26-
2723
// user-info is available on any origin
2824
app.addHook('onSend', (request, reply, payload, done) => {
2925
void reply.header(
@@ -53,8 +49,7 @@ export const userInfoController: FastifyPluginAsyncTypebox = async (app) => {
5349
},
5450
},
5551
async (request, reply) => {
56-
const token = getCloudToken(request);
57-
const user = await getCloudUser(identityClient, token);
52+
const user = getVerifiedUser(request, publicKey);
5853

5954
if (!user) {
6055
return reply.status(401).send();

packages/server/shared/src/lib/system/system-prop.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ export enum AppSystemProp {
8282
SHOW_DEMO_HOME_PAGE = 'SHOW_DEMO_HOME_PAGE',
8383

8484
FRONTEGG_URL = 'FRONTEGG_URL',
85-
FRONTEGG_CLIENT_ID = 'FRONTEGG_CLIENT_ID',
86-
FRONTEGG_API_KEY = 'FRONTEGG_API_KEY',
87-
FRONTEGG_APP_ID = 'FRONTEGG_APP_ID',
85+
FRONTEGG_PUBLIC_KEY = 'FRONTEGG_PUBLIC_KEY',
8886

8987
ENGINE_URL = 'ENGINE_URL',
9088
TELEMETRY_MODE = 'TELEMETRY_MODE',

packages/shared/src/lib/flag/flag.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ export enum FlagId {
5858
DARK_THEME_ENABLED = 'DARK_THEME_ENABLED',
5959
ENVIRONMENT_ID = 'ENVIRONMENT_ID',
6060
FRONTEGG_URL = 'FRONTEGG_URL',
61-
FRONTEGG_CLIENT_ID = 'FRONTEGG_CLIENT_ID',
62-
FRONTEGG_APP_ID = 'FRONTEGG_APP_ID',
6361
CLOUD_CONNECTION_PAGE_ENABLED = 'CLOUD_CONNECTION_PAGE_ENABLED',
6462
SHOW_DEMO_HOME_PAGE = 'SHOW_DEMO_HOME_PAGE',
6563
OAUTH_PROXY_URL = 'OAUTH_PROXY_URL',

0 commit comments

Comments
 (0)