import { JwtPayload } from './jsonwebtoken-type' ; import { checkMandatoryValue , JwtKeyMapping , readPropertyWithWarn } from './jwt' ; internal export const mappingTenantFields = { id : { keyInJwt : 'zid' , extractorFunction : tenantId } , name : { keyInJwt : 'zdn' , extractorFunction : tenantName } } ; param jwtPayload returns internal export function tenantId ( jwtPayload ) { return readPropertyWithWarn ( jwtPayload , mappingTenantFields . id . keyInJwt ) ; } param jwtPayload returns internal export function tenantName ( jwtPayload ) { const extAttr = readPropertyWithWarn ( jwtPayload , 'ext_attr' ) ; if ( extAttr ) { return readPropertyWithWarn ( extAttr , 'zdn' ) ; } } internal export interface Tenant { id : string ; name ? : string ; } param jwtPayload returns internal export function tenantFromJwt ( jwtPayload ) { checkMandatoryValue ( 'id' , mappingTenantFields , jwtPayload ) ; return { id : tenantId ( jwtPayload ) ! , name : tenantName ( jwtPayload ) } ; } param userTokenPayload param providerTokenPayload returns internal export function isIdenticalTenant ( userTokenPayload , providerTokenPayload ) { return ( readPropertyWithWarn ( userTokenPayload , mappingTenantFields . id . keyInJwt ) === readPropertyWithWarn ( providerTokenPayload , mappingTenantFields . id . keyInJwt ) ) ; }