Skip to content

Commit

Permalink
Merge pull request #69 from JustaName-id/ghadi/telegram-verfications-fix
Browse files Browse the repository at this point in the history
feat: change auth url telegram
  • Loading branch information
Ghadi8 authored Nov 1, 2024
2 parents 71100d4 + 004b6ee commit 36eec92
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 12 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,22 +21,16 @@ 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(
params: TelegramCallback
): Promise<TelegramCredential> {
const { hash, ...telegramData } = params;
const { hash, state, ...telegramData } = params;

const dataCheckString = Object.keys(telegramData)
.sort()
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
4 changes: 4 additions & 0 deletions k8s-staging/staging-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
key: ORIGIN
- objectName: domain
key: DOMAIN
- objectName: telegram_static_page_url
key: TELEGRAM_STATIC_PAGE_URL


parameters:
Expand Down Expand Up @@ -115,3 +117,5 @@ spec:
objectAlias: origin
- path: DOMAIN
objectAlias: domain
- path: TELEGRAM_STATIC_PAGE_URL
objectAlias: telegram_static_page_url
5 changes: 5 additions & 0 deletions k8s-staging/vc-api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ spec:
secretKeyRef:
name: foosecret-verifications
key: DOMAIN
- name: TELEGRAM_STATIC_PAGE_URL
valueFrom:
secretKeyRef:
name: foosecret-verifications
key: TELEGRAM_STATIC_PAGE_URL
---
apiVersion: v1
kind: Service
Expand Down
5 changes: 4 additions & 1 deletion k8s/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ spec:
key: ORIGIN
- objectName: domain
key: DOMAIN

- objectName: telegram_static_page_url
key: TELEGRAM_STATIC_PAGE_URL

parameters:
region: eu-central-1
Expand Down Expand Up @@ -111,3 +112,5 @@ spec:
objectAlias: origin
- path: DOMAIN
objectAlias: domain
- path: TELEGRAM_STATIC_PAGE_URL
objectAlias: telegram_static_page_url
5 changes: 5 additions & 0 deletions k8s/vc-api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ spec:
secretKeyRef:
name: foosecret-verifications
key: DOMAIN
- name: TELEGRAM_STATIC_PAGE_URL
valueFrom:
secretKeyRef:
name: foosecret-verifications
key: TELEGRAM_STATIC_PAGE_URL
---
apiVersion: v1
kind: Service
Expand Down

0 comments on commit 36eec92

Please sign in to comment.