Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add HTML domain verification
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 2, 2020
1 parent 5334cb1 commit e160f8e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/config/configuration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Configuration {

meta: {
totpServiceName: string;
domainVerificationFile: string;
};

caching: {
Expand Down
2 changes: 2 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const configuration: Configuration = {
frontendUrl: process.env.FRONTEND_URL ?? 'http://localhost:3000',
meta: {
totpServiceName: process.env.TOPT_SERVICE_NAME ?? 'Staart',
domainVerificationFile:
process.env.DOMAIN_VERIFICATION_FILE ?? 'staart-verify.txt',
},
caching: {
geolocationLruSize: int(process.env.GEOLOCATION_LRU_SIZE, 100),
Expand Down
3 changes: 2 additions & 1 deletion src/modules/domains/domains.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { DnsModule } from '../dns/dns.module';
import { PrismaModule } from '../prisma/prisma.module';
import { TokensService } from '../tokens/tokens.service';
import { DomainController } from './domains.controller';
import { DomainsService } from './domains.service';

@Module({
imports: [PrismaModule, TokensService, DnsModule],
imports: [PrismaModule, TokensService, DnsModule, ConfigModule],
controllers: [DomainController],
providers: [DomainsService],
})
Expand Down
15 changes: 13 additions & 2 deletions src/modules/domains/domains.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
domains,
domainsCreateInput,
domainsOrderByInput,
domainsWhereInput,
domainsWhereUniqueInput,
} from '@prisma/client';
import got from 'got';
import { BadRequestError } from 'passport-headerapikey';
import { DnsService } from '../dns/dns.service';
import { Expose } from '../prisma/prisma.interface';
Expand All @@ -20,7 +22,6 @@ import {
DOMAIN_VERIFICATION_HTML,
DOMAIN_VERIFICATION_TXT,
} from './domains.constants';
import got from 'got';
import { DomainVerificationMethods } from './domains.interface';

@Injectable()
Expand All @@ -29,6 +30,7 @@ export class DomainsService {
private prisma: PrismaService,
private tokensService: TokensService,
private dnsService: DnsService,
private configService: ConfigService,
) {}

async createDomain(
Expand Down Expand Up @@ -96,7 +98,16 @@ export class DomainsService {
});
} else throw new BadRequestError('TXT record not found');
} else if (method === DOMAIN_VERIFICATION_HTML) {
if ('ok') {
let verified = false;
try {
const { body } = await got(
`http://${domain.domain}/.well-known/${this.configService.get<string>(
'meta.domainVerificationFile' ?? 'staart-verify.txt',
)}`,
);
verified = body.includes(domain.verificationCode);
} catch (error) {}
if (verified) {
await this.prisma.domains.update({
where: { id },
data: { isVerified: true },
Expand Down

0 comments on commit e160f8e

Please sign in to comment.