[英]Unable to integrate Duo Web SDK with angular application
假设角度4和5。
首先,下载js文件( https://api.duosecurity.com/frame/hosted/Duo-Web-v2.js ),然后将其保存在angular项目的素材文件夹中。 打开它并更改以下行:
if (iframe) {
为了这
if (false && iframe) {
这样,您可以确保通过调用ngAfterViewInit始终加载iframe。
在您按下按钮时将调用并加载的组件中,添加以下行:
import * as Duo from '../../../../assets/duo/Duo-Web-v2'
在ngAfterViewInit(当然,所有角度渲染均已完成的地方,您可以在任何需要的地方调用此Duo.init方法)中添加以下内容:
ngAfterViewInit() {
Duo.init({
iframe: "duo_iframe",
host: this.duo.host,
sig_request: this.duo.sig_request,
submit_callback: this.twoFactorVerify.bind(this),
});
}
其中this.duo是包含主机和sig_request信息的对象。 我使用了回调选项,因为它是SPA应用程序,所以我不想重新加载页面。 另外,我使用bind(this),因为我需要组件上下文,而不是调用回调的js上下文。 回调函数是这样的:
twoFactorVerify(response: any) {
console.log(response.elements.sig_response.value);
this.serviceApi.post('/two_factor_verify',
{ sig_response: response.elements.sig_response.value }) bla, bla...
...
}
其中sig_response是DUO服务的响应。
在HTML模板中,只需添加:
<iframe id="duo_iframe" align=center></iframe>
而已。
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.