You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
import {Instantiable, isInstantiable} from '../di'
|
|
import {AuthenticatableRepository} from './types'
|
|
import {hasOwnProperty} from '../util'
|
|
import {LoginProviderConfig} from './provider/LoginProvider'
|
|
|
|
export interface AuthenticationConfig {
|
|
storage: Instantiable<AuthenticatableRepository>,
|
|
providers?: {
|
|
[key: string]: LoginProviderConfig
|
|
},
|
|
}
|
|
|
|
export function isAuthenticationConfig(what: unknown): what is AuthenticationConfig {
|
|
if ( typeof what !== 'object' || !what ) {
|
|
return false
|
|
}
|
|
|
|
if ( !hasOwnProperty(what, 'storage') || !hasOwnProperty(what, 'sources') ) {
|
|
return false
|
|
}
|
|
|
|
if ( !isInstantiable(what.storage) || !(what.storage.prototype instanceof AuthenticatableRepository) ) {
|
|
return false
|
|
}
|
|
|
|
if ( typeof what.sources !== 'object' ) {
|
|
return false
|
|
}
|
|
|
|
for ( const key in what.sources ) {
|
|
if ( !hasOwnProperty(what.sources, key) ) {
|
|
continue
|
|
}
|
|
|
|
const source = what.sources[key]
|
|
if ( !isInstantiable(source) || !(source.prototype instanceof AuthenticatableRepository) ) {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|