Files
speckle-server/packages/server/modules/workspaces/domain/sso/logic.ts
T
Kristaps Fabians Geikins 4b06f42db7 chore(server): run TS files directly (no compilation) (#5134)
* sort of works

* type fixes

* added option to run old way too
2025-07-23 11:20:40 +02:00

40 lines
1.1 KiB
TypeScript

import type {
OidcProfile,
SpeckleOidcProfile,
UserSsoSessionRecord
} from '@/modules/workspaces/domain/sso/types'
import type { UnknownObject, UserinfoResponse } from 'openid-client'
/**
* Get the default expiration time for an SSO session based on the current time.
* TODO: Is 7 days a good default session length?
*/
export const getDefaultSsoSessionExpirationDate = (): Date => {
const now = new Date()
now.setDate(now.getDate() + 7)
return now
}
export const isValidSsoSession = (session: UserSsoSessionRecord): boolean => {
return session.validUntil.getTime() > new Date().getTime()
}
export const isValidOidcProfile = (
profile: UserinfoResponse<UnknownObject, UnknownObject>
): profile is OidcProfile => {
return !!profile.email || !!profile.upn
}
const isSpeckleOidcProfile = (
profile: OidcProfile
): profile is OidcProfile<SpeckleOidcProfile> => {
return Object.hasOwn(profile, 'email')
}
/**
* Special handling required in case we encounter Entra ID with a particular configuration.
*/
export const getEmailFromOidcProfile = (profile: OidcProfile): string => {
return isSpeckleOidcProfile(profile) ? profile.email : profile.upn
}