Skip to content

Commit

Permalink
cleanup (#3401)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakprabhakara authored Dec 25, 2024
1 parent 3f586ef commit 3317b35
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 310 deletions.
4 changes: 0 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ BOXYHQ_HOSTED=0
# Setup link expiry in days
SETUP_LINK_EXPIRY_DAYS=3

# Ory integration. You need BOXYHQ_LICENSE_KEY to be set to use this.
ENTERPRISE_ORY_SDK_TOKEN=
ENTERPRISE_ORY_PROJECT_ID=

# Uncomment below if you wish to opt-out of sending `profile` scope in OIDC Provider Authorization Request
#OPENID_REQUEST_PROFILE_SCOPE=false

Expand Down
4 changes: 0 additions & 4 deletions lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ const jacksonOptions: JacksonOption = {
},
setupLinkExpiryDays,
boxyhqHosted,
ory: {
projectId: process.env.ENTERPRISE_ORY_PROJECT_ID,
sdkToken: process.env.ENTERPRISE_ORY_SDK_TOKEN,
},
ssoTraces,
};

Expand Down
15 changes: 5 additions & 10 deletions npm/src/controller/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@ import { JacksonError } from './error';
import { IndexNames, appID, transformConnections, transformConnection, isConnectionActive } from './utils';
import oidcConnection from './connection/oidc';
import samlConnection from './connection/saml';
import { OryController } from '../ee/ory/ory';

export class ConnectionAPIController implements IConnectionAPIController {
private connectionStore: Storable;
private opts: JacksonOption;
private eventController: IEventController;
private oryController: OryController;

constructor({ connectionStore, opts, eventController, oryController }) {
constructor({ connectionStore, opts, eventController }) {
this.connectionStore = connectionStore;
this.opts = opts;
this.eventController = eventController;
this.oryController = oryController;
}

/**
Expand Down Expand Up @@ -198,7 +195,7 @@ export class ConnectionAPIController implements IConnectionAPIController {
): Promise<SAMLSSORecord> {
metrics.increment('createConnection');

const connection = await samlConnection.create(body, this.connectionStore, this.oryController);
const connection = await samlConnection.create(body, this.connectionStore);

await this.eventController.notify('sso.created', connection);

Expand All @@ -221,7 +218,7 @@ export class ConnectionAPIController implements IConnectionAPIController {
throw new JacksonError('Please set OpenID response handler path (oidcPath) on Jackson', 500);
}

const connection = await oidcConnection.create(body, this.connectionStore, this.oryController);
const connection = await oidcConnection.create(body, this.connectionStore);

await this.eventController.notify('sso.created', connection);

Expand Down Expand Up @@ -378,8 +375,7 @@ export class ConnectionAPIController implements IConnectionAPIController {
const connection = await samlConnection.update(
body,
this.connectionStore,
this.getConnections.bind(this),
this.oryController
this.getConnections.bind(this)
);

if ('deactivated' in body) {
Expand All @@ -406,8 +402,7 @@ export class ConnectionAPIController implements IConnectionAPIController {
const connection = await oidcConnection.update(
body,
this.connectionStore,
this.getConnections.bind(this),
this.oryController
this.getConnections.bind(this)
);

if ('deactivated' in body) {
Expand Down
40 changes: 2 additions & 38 deletions npm/src/controller/connection/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import {
validateSortOrder,
} from '../utils';
import { JacksonError } from '../error';
import { OryController } from '../../ee/ory/ory';

const oidc = {
create: async (
body: OIDCSSOConnectionWithDiscoveryUrl | OIDCSSOConnectionWithMetadata,
connectionStore: Storable,
oryController: OryController
connectionStore: Storable
) => {
validateSSOConnection(body, 'oidc');

Expand Down Expand Up @@ -87,9 +85,6 @@ const oidc = {
record.clientID = dbutils.keyDigest(dbutils.keyFromParts(tenant, product, oidcClientId));

const exists = await connectionStore.get(record.clientID);
const oryProjectId = exists?.ory?.projectId;
const oryOrganizationId = exists?.ory?.organizationId;

if (exists) {
connectionClientSecret = exists.clientSecret;
} else {
Expand All @@ -98,21 +93,6 @@ const oidc = {

record.clientSecret = connectionClientSecret;

const oryRes = await oryController.createConnection(
{
sdkToken: undefined,
projectId: oryProjectId,
domains: body.ory?.domains,
organizationId: oryOrganizationId,
error: undefined,
},
tenant,
product
);
if (oryRes) {
record.ory = oryRes;
}

await connectionStore.put(
record.clientID,
record,
Expand All @@ -134,8 +114,7 @@ const oidc = {
update: async (
body: UpdateOIDCConnectionParams,
connectionStore: Storable,
connectionsGetter: IConnectionAPIController['getConnections'],
oryController: OryController
connectionsGetter: IConnectionAPIController['getConnections']
) => {
const {
defaultRedirectUrl,
Expand Down Expand Up @@ -234,21 +213,6 @@ const oidc = {
record['deactivated'] = body.deactivated;
}

const oryRes = await oryController.updateConnection(
{
sdkToken: undefined,
projectId: _savedConnection.ory?.projectId,
domains: _savedConnection.ory?.domains,
organizationId: _savedConnection.ory?.organizationId,
error: undefined,
},
_savedConnection.tenant,
_savedConnection.product
);
if (oryRes) {
record.ory = oryRes;
}

await connectionStore.put(
clientInfo?.clientID,
record,
Expand Down
39 changes: 2 additions & 37 deletions npm/src/controller/connection/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
validateSortOrder,
} from '../utils';
import { JacksonError } from '../error';
import { OryController } from '../../ee/ory/ory';

async function fetchMetadata(resource: string) {
try {
Expand Down Expand Up @@ -60,8 +59,7 @@ function validateMetadataURL(metadataUrl: string) {
const saml = {
create: async (
body: SAMLSSOConnectionWithRawMetadata | SAMLSSOConnectionWithEncodedMetadata,
connectionStore: Storable,
oryController: OryController
connectionStore: Storable
) => {
const {
encodedRawMetadata,
Expand Down Expand Up @@ -155,8 +153,6 @@ const saml = {
}

const exists = await connectionStore.get(record.clientID);
const oryProjectId = exists?.ory?.projectId;
const oryOrganizationId = exists?.ory?.organizationId;

if (exists) {
connectionClientSecret = exists.clientSecret;
Expand All @@ -166,21 +162,6 @@ const saml = {

record.clientSecret = connectionClientSecret;

const oryRes = await oryController.createConnection(
{
sdkToken: undefined,
projectId: oryProjectId,
domains: body.ory?.domains,
organizationId: oryOrganizationId,
error: undefined,
},
tenant,
product
);
if (oryRes) {
record.ory = oryRes;
}

await connectionStore.put(
record.clientID,
record,
Expand All @@ -206,8 +187,7 @@ const saml = {
update: async (
body: UpdateSAMLConnectionParams,
connectionStore: Storable,
connectionsGetter: IConnectionAPIController['getConnections'],
oryController: OryController
connectionsGetter: IConnectionAPIController['getConnections']
) => {
const {
encodedRawMetadata, // could be empty
Expand Down Expand Up @@ -319,21 +299,6 @@ const saml = {
record['identifierFormat'] = body.identifierFormat;
}

const oryRes = await oryController.updateConnection(
{
sdkToken: undefined,
projectId: _savedConnection.ory?.projectId,
domains: _savedConnection.ory?.domains,
organizationId: _savedConnection.ory?.organizationId,
error: undefined,
},
_savedConnection.tenant,
_savedConnection.product
);
if (oryRes) {
record.ory = oryRes;
}

await connectionStore.put(
clientInfo?.clientID,
record,
Expand Down
Loading

0 comments on commit 3317b35

Please sign in to comment.