Skip to content

Commit

Permalink
feat: change auth url telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghadi8 committed Nov 1, 2024
1 parent 71100d4 commit c30813e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions apps/vc-api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TWITTER_CLIENT_SECRET=<YOUR_TWITTER

TELEGRAM_BOT_TOKEN=<YOUR_TELEGRAM_BOT_TOKEN>
TELEGRAM_BOT_USERNAME=<YOUR_TELEGRAM_BOT_USERNAME>
TELEGRAM_STATIC_PAGE_URL=<YOUR_TELEGRAM_STATIC_PAGE_URL>

DISCORD_CLIENT_ID=<YOUR_DISCORD_CLIENT_ID>
DISCORD_CLIENT_SECRET=<YOUR_DISCORD_CLIENT_SECRET>
Expand Down
3 changes: 3 additions & 0 deletions apps/vc-api/src/config/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class EnvironmentVariables implements Environment{
@IsString({message: 'TELEGRAM_BOT_USERNAME must be a string'})
TELEGRAM_BOT_USERNAME!: string;

@IsString({message: 'TELEGRAM_STATIC_PAGE_URL must be a string'})
TELEGRAM_STATIC_PAGE_URL!: string;

@IsString({message: 'JWT_SECRET must be a string'})
JWT_SECRET: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ export class TelegramSocialResolver extends AbstractSocialResolver<
}
getAuthUrl(authUrlRequest: GetAuthUrlRequest): string {
const state = this.encryptState(authUrlRequest);
return `<html>
<body>
<script async src="https://telegram.org/js/telegram-widget.js?15"
data-telegram-login="${this.environmentGetter.getTelegramBotUsername()}"
data-size="large"
data-auth-url="${this.environmentGetter.getApiDomain()}/credentials/socials/telegram/callback?state=${state}"
data-request-access="write">
</script>
</body>
</html>`;

const telegramStaticPageUrl = this.environmentGetter.getTelegramStaticPageUrl();

return `${telegramStaticPageUrl}?state=${state}`;
}

async extractCredentialSubject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class EnvironmentGetter implements IEnvironmentGetter {
return this.configService.get<string>('TELEGRAM_BOT_USERNAME');
}

getTelegramStaticPageUrl(): string {
return this.configService.get<string>('TELEGRAM_STATIC_PAGE_URL');
}

getEncryptKey(): string {
return this.configService.get<string>('ENCRYPT_KEY');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface IEnvironmentGetter {
getTwitterClientSecret(): string;
getTelegramBotToken(): string;
getTelegramBotUsername(): string;
getTelegramStaticPageUrl(): string;
getEncryptKey(): string;
getEncryptSalt(): string;
getResendApiKey(): string;
Expand Down
2 changes: 2 additions & 0 deletions apps/vc-api/src/core/domain/entities/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class Environment {

TELEGRAM_BOT_USERNAME!: string;

TELEGRAM_STATIC_PAGE_URL!: string;

JWT_SECRET!: string;

ENCRYPT_KEY!: string;
Expand Down

0 comments on commit c30813e

Please sign in to comment.