23 lines
702 B
TypeScript
23 lines
702 B
TypeScript
|
import {ClientRepository, OAuth2Client, isOAuth2Client} from '../types'
|
||
|
import {Awaitable, ErrorWithContext, Maybe} from '../../../util'
|
||
|
import {Inject, Injectable} from '../../../di'
|
||
|
import {Config} from '../../../service/Config'
|
||
|
|
||
|
@Injectable()
|
||
|
export class ConfigClientRepository extends ClientRepository {
|
||
|
@Inject()
|
||
|
protected readonly config!: Config
|
||
|
|
||
|
find(id: string): Awaitable<Maybe<OAuth2Client>> {
|
||
|
const client = this.config.get(`oauth2.clients.${id}`)
|
||
|
if ( !isOAuth2Client(client) ) {
|
||
|
throw new ErrorWithContext('Invalid OAuth2 client configuration', {
|
||
|
id,
|
||
|
client,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return client
|
||
|
}
|
||
|
}
|