gpt4 book ai didi

javascript - 如何在 Angular 应用中使用 Telegram 授权

转载 作者:行者123 更新时间:2023-12-04 08:11:27 24 4
gpt4 key购买 nike

我正在尝试以 Angular 实现电报授权。我已经创建了机器人并在我的 Windows 中放置了正确的主机设置。关注此 solution ,我的代码看起来一样。但它给了我一个错误

Refused to frame 'https://oauth.telegram.org/' because an ancestorviolates the following Content Security Policy directive:"frame-ancestors http://host.de".

@Component({
selector: 'app-telegram-login-widget',
template: `
<div #script style.display="none">
<ng-content></ng-content>
</div>`,
styleUrls: ['./telegram-login-widget.component.css']
})
export class TelegramLoginWidgetComponent implements AfterViewInit {

@ViewChild('script', {static: true}) script: ElementRef;

convertToScript() {
const element = this.script.nativeElement;
const script = document.createElement('script');
script.src = 'https://telegram.org/js/telegram-widget.js?5';
script.setAttribute('data-telegram-login', environment.telegramBotName);
script.setAttribute('data-size', 'large');
// Callback function in global scope
script.setAttribute('data-onauth', 'loginViaTelegram(user)');
script.setAttribute('data-request-access', 'write');
element.parentElement.replaceChild(script, element);
}

ngAfterViewInit() {
this.convertToScript();
}

}

最佳答案

Content-Security-Policy Telegram 小部件仅允许有限的主机列表将其包含为 iframe。
要将您的域添加到允许列表中,您必须将机器人链接到您的域,请参阅 docs :

Once you have chosen a bot, send the /setdomain command to @Botfather to link your website's domain to the bot.

关于javascript - 如何在 Angular 应用中使用 Telegram 授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65930851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com