import { Inject, Injectable } from '@nestjs/common'; import { Repository } from 'typeorm'; import { OAuth2ClientAuthorization } from './oauth2-client-authorization.entity'; import { OAuth2ClientURL, OAuth2ClientURLType, } from './oauth2-client-url.entity'; import { OAuth2Client } from './oauth2-client.entity'; @Injectable() export class OAuth2ClientService { constructor( @Inject('CLIENT_REPOSITORY') private clientRepository: Repository, @Inject('CLIENT_URL_REPOSITORY') private clientUrlRepository: Repository, @Inject('CLIENT_AUTHORIZATION_REPOSITORY') private clientAuthRepository: Repository, ) {} public async getById(id: string | number): Promise { let client: OAuth2Client; if (typeof id === 'string') { client = await this.clientRepository.findOne({ client_id: id }); } else { client = await this.clientRepository.findOne({ id }); } return client; } public async getClientURLs( id: string, type?: OAuth2ClientURLType, ): Promise { return this.clientUrlRepository.find({ client: { client_id: id }, type }); } public async checkRedirectURI(id: string, url: string): Promise { return !!(await this.clientUrlRepository.findOne({ client: { client_id: id }, url, type: OAuth2ClientURLType.REDIRECT_URI, })); } }