passport
根据现有认证方式,梳理的认证模块。
基础认证接口:
ts
export interface IPassportService {
login(redirectUrl?: string): void
logout(): void
fetchUserInfo(): Promise<IUserInfo>
fetchPermission(): Promise<IPermissionData>
}
梳理uums
认证服务:
ts
export class BasePassportService implements IPassportService {}
梳理sso
认证服务:
ts
export class SsoPassportService extends BasePassportService {}
基于上述扩展微前端
认证服务:
ts
export class MicroPassportService extends SsoPassportService {}
上述列举认证服务继承关系,
其中fs-web-library
中默认为sso
认证方式(早期为uums
,随着sso
的稳定并全平台推广,内置默认认证方式也改为了sso
)。
梳理出认证模块的抽象类有助于扩展各类认证方式,从而避免更换认证方式时侵入业务,只需实现对应的抽象类即可,无需修改业务代码。
如wms
仓库管理系统开发时,将认证方式从uums
改为sso
认证,只需注入SsoPassportService
服务即可,
ts
provideServiceContext(ServiceType.passport, new SsoPassportService())
详见提交4eb8d96fc8b048872c5a7360ef582dad4ab460ae
再如dcs
文控管理系统开发时,需要作为子应用接入mom
平台,则需要在微前端环境中注入MicroPassportService
服务即可,
ts
// mom微前端 认证
if (micro.isMicroApp) {
provideServiceContext(ServiceType.passport, new MicroPassportService())
}