我可以在移动浏览器上自动读取OTP吗? [英] Can I Auto read OTP on Mobile Browsers?

查看:64
本文介绍了我可以在移动浏览器上自动读取OTP吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在移动浏览器上自动读取登录OTP.我的Web应用程序是在Angular 7中构建的.

I am working on auto reading a login OTP on a mobile browser. My web application is built in Angular 7.

用户单击登录后,就会通过AWS将OTP发送到6位数代码的用户手机.

Once the user clicks on login, an OTP is sent via AWS to the user's mobile with a 6 digit code.

我已经查询了Google的SMS Retriever API,但这对我的情况没有帮助.

I have looked up Google's SMS Retriever API but it does not help my case.

是否可以从移动浏览器读取OTP?

Is reading an OTP from a mobile browser possible?

推荐答案

是的,现在可以做到.Chrome在版本84及更高版本中发布了此功能.借助 WEBOTP API ,我们可以在网络上为移动设备检测OTP.

Yes, this is possible now. Chrome release this feature in version 84 and above. With the help of WEBOTP API we can detect OTP on the web for mobile devices.

代码-

if ('OTPCredential' in window) { 
  window.addEventListener('DOMContentLoaded', e => {
    const ac = new AbortController();
    navigator.credentials.get({
      otp: { transport:['sms'] },
      signal: ac.signal
    }).then(otp => {
      alert(otp.code)
    }).catch(err => {
      console.log(err)
    });
  })
} else {
  alert('WebOTP not supported!.')
}

SMS格式-

@www.amazon.com #1598.

此处@ www.amazon.com是将进行验证的域,而otp是1598

演示链接- https://jyotishman.github.io/webOTPAPI/

这篇关于我可以在移动浏览器上自动读取OTP吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆