我有一个 API 需要在获得长期 session token 之前使用 HOTP/TOTP 代码注册一次。
iOS 应用是否可以(理论上)“调用”修改版的 Google Authenticator,允许一次性交换 HOTP/TOTP 代码?
我假设 Google Authenticator 的修改版本会发出像
这样的提示"Are you sure you want to send a code for XXX to YYY?"
有什么办法可以实现这种情况吗?缺少这个,我将不得不引导用户在应用程序之间进行多任务处理,这是我的消费者不知道如何在 iOS 上执行的功能。 (双击手机或iPad底部的按钮躲避他们)
一些让我认为这是可能的想法:
我看到 Safari 中的网络链接会打开设备上的应用程序,或者在安装时打开应用程序而不是 .mobile 版本的网站(Foursquare、Facebook 等)
应用可以在 Safari 或 Chrome 中打开网站
综合考虑这些想法,我可以添加一个包含 HOTP 代码的 URL 参数,并通过 HTTPS 将其“弹回”,但我想要一个更本地化的解决方案
注意事项:我在 Security.SE 上提问,因为我认为这里的人可能最了解 iOS 沙盒,因为这里所需的概念和技能在概念上可能类似于 ASLR and DEP which have 74+ questions on the site .
最佳答案
是的,只需使用共享的 UIApplication
对象和 openURL
方法即可。该方案在 KeyUriFormat page 中有详细说明。 Google 身份验证器 wiki。
代码应该是这样的:
NSString *issuer = @"Example";
NSString *accountname = @"alice@google.com";
NSString *label = [NSString stringWithFormat:@"%@:%@",issuer,accountname];
NSString *secret = @"JBSWY3DPEHPK3PXP";
NSString *algorithm = @"SHA1";
NSString *digits = @"6";
NSString *period = @"30";
NSString *urlPath = [NSString stringWithFormat:@"otpauth://totp/%@?secret=%@&issuer=%@&algorithm=%@&digits=%@&period=%@",label,secret,issuer,algorithm,digits,period];
NSURL *url = [NSURL URLWithString:urlPath];
[[UIApplication sharedApplication] openURL:url];
但是,目前似乎有this bug这会使当前版本的 iOS 应用程序崩溃(我已经测试过了)。
:(
或者,您可以在您的应用中加入您自己的 TOTP 实现。并不太复杂,我实际上已经整理了一个简单的例子here .
关于ios - iOS 应用程序是否可以与 Google Authenticator 通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22356552/