mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor(core,schemas): remove get provider properties method (#4927)
* refactor(core,schemas): remove get provider properties method remove get provider properties method * chore(core): adjust the comment adjust the comment * fix(console): fix console type error fix console type error, remove providerProperties
This commit is contained in:
parent
e82ea0a815
commit
3b3bfd750a
10 changed files with 15 additions and 39 deletions
|
@ -12,7 +12,7 @@ import * as styles from './index.module.scss';
|
|||
|
||||
type Props = {
|
||||
ssoConnectorId: string;
|
||||
} & Pick<SsoConnectorWithProviderConfig, 'providerName' | 'providerProperties'>;
|
||||
} & Pick<SsoConnectorWithProviderConfig, 'providerName' | 'providerConfig'>;
|
||||
|
||||
/**
|
||||
* TODO: Should align this with the guard `samlServiceProviderMetadataGuard` defined in {@link logto/core/src/sso/types/saml.ts}.
|
||||
|
@ -23,7 +23,7 @@ const providerPropertiesGuard = z.object({
|
|||
entityId: z.string().min(1),
|
||||
});
|
||||
|
||||
function BasicInfo({ ssoConnectorId, providerName, providerProperties }: Props) {
|
||||
function BasicInfo({ ssoConnectorId, providerName, providerConfig }: Props) {
|
||||
const { tenantEndpoint } = useContext(AppDataContext);
|
||||
const { applyDomain: applyCustomDomain } = useCustomDomain();
|
||||
|
||||
|
@ -44,7 +44,7 @@ function BasicInfo({ ssoConnectorId, providerName, providerProperties }: Props)
|
|||
);
|
||||
}
|
||||
|
||||
const result = providerPropertiesGuard.safeParse(providerProperties);
|
||||
const result = providerPropertiesGuard.safeParse(providerConfig);
|
||||
|
||||
/**
|
||||
* Used fallback to show the default value anyways but the cases should not happen.
|
||||
|
|
|
@ -63,7 +63,7 @@ function Guide<T extends SsoProviderName>({ isOpen, connector, onClose, isReadOn
|
|||
id: ssoConnectorId,
|
||||
connectorName: ssoConnectorName,
|
||||
providerName,
|
||||
providerProperties,
|
||||
providerConfig,
|
||||
} = connector;
|
||||
|
||||
const api = useApi();
|
||||
|
@ -138,7 +138,7 @@ function Guide<T extends SsoProviderName>({ isOpen, connector, onClose, isReadOn
|
|||
<BasicInfo
|
||||
ssoConnectorId={ssoConnectorId}
|
||||
providerName={providerName}
|
||||
providerProperties={providerProperties}
|
||||
providerConfig={providerConfig}
|
||||
/>
|
||||
</GuideCard>
|
||||
{providerName === SsoProviderName.OIDC ? (
|
||||
|
|
|
@ -5,7 +5,7 @@ import type {
|
|||
SupportedSsoConnector,
|
||||
SsoProviderName,
|
||||
} from '@logto/schemas';
|
||||
import { conditional, trySafe } from '@silverhand/essentials';
|
||||
import { trySafe } from '@silverhand/essentials';
|
||||
|
||||
import RequestError from '#src/errors/RequestError/index.js';
|
||||
import {
|
||||
|
@ -58,10 +58,6 @@ export const parseConnectorConfig = (
|
|||
return result.data;
|
||||
};
|
||||
|
||||
/*
|
||||
Safely fetch and parse the detailed connector config from provider.
|
||||
Return undefined if failed to fetch or parse the config.
|
||||
*/
|
||||
export const fetchConnectorProviderDetails = async (
|
||||
connector: SupportedSsoConnector,
|
||||
tenantId: string
|
||||
|
@ -70,21 +66,19 @@ export const fetchConnectorProviderDetails = async (
|
|||
|
||||
const { logo, constructor } = ssoConnectorFactories[providerName];
|
||||
|
||||
/*
|
||||
Safely fetch and parse the detailed connector config from provider.
|
||||
Return undefined if failed to fetch or parse the config.
|
||||
*/
|
||||
const providerConfig = await trySafe(async () => {
|
||||
const instance = new constructor(connector, tenantId);
|
||||
return instance.getConfig();
|
||||
});
|
||||
|
||||
const providerProperties = trySafe(() => {
|
||||
const instance = new constructor(connector, tenantId);
|
||||
return instance.getProperties();
|
||||
});
|
||||
|
||||
return {
|
||||
...connector,
|
||||
providerLogo: logo,
|
||||
...conditional(providerConfig && { providerConfig }),
|
||||
...conditional(providerProperties && { providerProperties }),
|
||||
providerConfig,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -25,10 +25,6 @@ export class GoogleWorkspaceSsoConnector extends OidcConnector implements Single
|
|||
});
|
||||
}
|
||||
|
||||
// OIDC connector doesn't have additional properties.
|
||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||
getProperties = () => undefined;
|
||||
|
||||
async getConfig() {
|
||||
return this.getOidcConfig();
|
||||
}
|
||||
|
|
|
@ -17,10 +17,6 @@ export class OidcSsoConnector extends OidcConnector implements SingleSignOn {
|
|||
super(parseConfigResult.data);
|
||||
}
|
||||
|
||||
// OIDC connector doesn't have additional properties.
|
||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
||||
getProperties = () => undefined;
|
||||
|
||||
async getConfig() {
|
||||
return this.getOidcConfig();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ConnectorError, ConnectorErrorCodes } from '@logto/connector-kit';
|
||||
import { type Optional } from '@silverhand/essentials';
|
||||
import { trySafe, type Optional } from '@silverhand/essentials';
|
||||
import * as saml from 'samlify';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
@ -84,7 +84,7 @@ class SamlConnector {
|
|||
*/
|
||||
async getSamlConfig(): Promise<SamlMetadata> {
|
||||
const serviceProvider = this.serviceProviderMetadata;
|
||||
const identityProvider = await this.getSamlIdpMetadata();
|
||||
const identityProvider = await trySafe(async () => this.getSamlIdpMetadata());
|
||||
return { serviceProvider, identityProvider };
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import assertThat from '#src/utils/assert-that.js';
|
|||
import SamlConnector from '../SamlConnector/index.js';
|
||||
import { type SingleSignOnFactory } from '../index.js';
|
||||
import { type SingleSignOn } from '../types/index.js';
|
||||
import { type SamlServiceProviderMetadata, samlConnectorConfigGuard } from '../types/saml.js';
|
||||
import { samlConnectorConfigGuard } from '../types/saml.js';
|
||||
import {
|
||||
type SingleSignOnConnectorSession,
|
||||
type CreateSingleSignOnSession,
|
||||
|
@ -45,13 +45,6 @@ export class SamlSsoConnector extends SamlConnector implements SingleSignOn {
|
|||
return entityId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Properties of the SAML service provider.
|
||||
*/
|
||||
getProperties(): SamlServiceProviderMetadata {
|
||||
return this.getSamlSpProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parsed SAML connector's config along with it's metadata. Throws error if config is invalid.
|
||||
*
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { type JsonObject, type SsoConnector } from '@logto/schemas';
|
||||
import { type Optional } from '@silverhand/essentials';
|
||||
|
||||
export * from './session.js';
|
||||
|
||||
|
@ -14,5 +13,4 @@ export abstract class SingleSignOn {
|
|||
abstract data: SsoConnector;
|
||||
abstract getConfig: () => Promise<JsonObject>;
|
||||
abstract getIssuer: () => Promise<string>;
|
||||
abstract getProperties: () => Optional<JsonObject>;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ export type SamlConnectorConfig = z.infer<typeof samlConnectorConfigGuard>;
|
|||
|
||||
const samlMetadataGuard = z.object({
|
||||
serviceProvider: samlServiceProviderMetadataGuard,
|
||||
identityProvider: samlIdentityProviderMetadataGuard,
|
||||
identityProvider: samlIdentityProviderMetadataGuard.optional(),
|
||||
});
|
||||
|
||||
export type SamlMetadata = z.infer<typeof samlMetadataGuard>;
|
||||
|
|
|
@ -47,7 +47,6 @@ export const ssoConnectorWithProviderConfigGuard = SsoConnectors.guard
|
|||
providerName: z.nativeEnum(SsoProviderName),
|
||||
providerLogo: z.string(),
|
||||
providerConfig: z.record(z.unknown()).optional(),
|
||||
providerProperties: z.record(z.unknown()).optional(),
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue