微软,呵呵。。。
今天,看到一则炸裂的消息“微软要求中国员工禁止使用安卓手机,未有iPhone手机员工为其发放iPhone”,不知道各位小伙伴是否看到~
我又用英文去搜了一下,确实如此!
那么,微软为何要如此大动干戈禁止国内员工用安卓手机呢?
按照微软官方的说法,是因为员工身份认证程序「Microsoft Authenticator」和「Identity Pass」应用程序只在Apple App Store和 Google Play Store上架,而并没有在国内安卓应用商店上架。
而对于国内的安卓机来说,是没有安装G Play应用框架的,在微软看来,没有安装G Play的安卓机就是不安全,所以,就一刀切了,它的认证应用也就不上架国内商店了,全员用IPhone了~
就我个人而言,我肯定反对微软这种对国产安卓机歧视的做法!
整个事件大概就是这样,作为技术人新闻始终都会过去的,我们还是得要研究技术,你是否思考过:我们的系统该如何接入这种身份认证服务「Microsoft Authenticator」呢?
比如我们经常用的Github,还比如咱们用的最多的堡垒机,都会有二次认证服务,如下图:
# 接入流程
我之前做量化系统的时候,刚好研究过该类认证服务的接入问题,我给大家阐述一下整体的接入流程:
添加依赖库:首先需要引入支持TOTP的库,com.warrenstrange的Google Authenticator是一个流行的选择。
生成密钥:为每个用户生成一个唯一的密钥,这个密钥会被用户用于Google Authenticator应用的配置。
生成二维码:用户扫描这个二维码来在Google Authenticator应用中配置账号。
验证TOTP:验证用户在Google Authenticator应用中生成的一次性密码(TOTP)是否正确。
接下来,我给出具体的代码实现~
import com.warrenstrange.googleauth.GoogleAuthenticator;import com.warrenstrange.googleauth.GoogleAuthenticatorKey;public class TwoFactorAuth {public static void main(String[] args) {GoogleAuthenticator gAuth = new GoogleAuthenticator();final GoogleAuthenticatorKey key = gAuth.createCredentials();String secret = key.getKey();System.out.println("Secret key: " + secret);}}
import com.google.zxing.BarcodeFormat;import com.google.zxing.WriterException;import com.google.zxing.client.j2se.MatrixToImageWriter;import com.google.zxing.common.BitMatrix;import com.google.zxing.qrcode.QRCodeWriter;import com.warrenstrange.googleauth.GoogleAuthenticator;import com.warrenstrange.googleauth.GoogleAuthenticatorKey;import java.io.IOException;import java.nio.file.FileSystems;import java.nio.file.Path;public class GenerateQRCode {public static void main(String[] args) {GoogleAuthenticator gAuth = new GoogleAuthenticator();final GoogleAuthenticatorKey key = gAuth.createCredentials();String secret = key.getKey();String email = "[email protected]";String issuer = "ExampleApp";String barCodeUrl = getGoogleAuthenticatorBarCode(secret, email, issuer);System.out.println("QR Barcode URL: " + barCodeUrl);try {generateQRCodeImage(barCodeUrl, 350, 350, "QRCode.png");} catch (WriterException | IOException e) {e.printStackTrace();}}private static String getGoogleAuthenticatorBarCode(String secretKey, String account, String issuer) {return "otpauth://totp/"+ issuer + ":"+ account + "?secret=" + secretKey+ "&issuer=" + issuer;}private static void generateQRCodeImage(String text, int width, int height, String filePath)throws WriterException, IOException {QRCodeWriter qrCodeWriter = new QRCodeWriter();BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);Path path = FileSystems.getDefault().getPath(filePath);MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);}}
import com.warrenstrange.googleauth.GoogleAuthenticator;public class VerifyTOTP {public static void main(String[] args) {GoogleAuthenticator gAuth = new GoogleAuthenticator();String secretKey = "用户的密钥";int verificationCode = 123456; // 用户从Google Authenticator应用中输入的验证码boolean isCodeValid = gAuth.authorize(secretKey, verificationCode);if (isCodeValid) {System.out.println("验证成功");} else {System.out.println("验证失败");}}}
回复关键字:ai ,获取AI工具安装包及《100+AI搞钱密码》