From e9b4ad504b6edc9a89b4f13efc7e1025ab9cadeb Mon Sep 17 00:00:00 2001 From: Adarsha Nepal <31477779+adars47@users.noreply.github.com> Date: Fri, 31 Jul 2020 14:20:25 +0545 Subject: [PATCH] Support for microsoft authenticator Microsoft authenticator needs that extra parameter to get the app name correct. --- PHPGangsta/GoogleAuthenticator.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/PHPGangsta/GoogleAuthenticator.php b/PHPGangsta/GoogleAuthenticator.php index bf7d116..19c011f 100644 --- a/PHPGangsta/GoogleAuthenticator.php +++ b/PHPGangsta/GoogleAuthenticator.php @@ -103,12 +103,16 @@ public function getQRCodeGoogleUrl($name, $secret, $title = null, $params = arra $width = !empty($params['width']) && (int) $params['width'] > 0 ? (int) $params['width'] : 200; $height = !empty($params['height']) && (int) $params['height'] > 0 ? (int) $params['height'] : 200; $level = !empty($params['level']) && array_search($params['level'], array('L', 'M', 'Q', 'H')) !== false ? $params['level'] : 'M'; - - $urlencoded = urlencode('otpauth://totp/'.$name.'?secret='.$secret.''); + + $urlencoded = urlencode('otpauth://totp/'); + //for microsoft authenticator to get the app name correct + if (isset($title)) { + $urlencoded .= urlencode(urlencode($title).":"); + } + $urlencoded .= urlencode($name.'?secret='.$secret); if (isset($title)) { $urlencoded .= urlencode('&issuer='.urlencode($title)); } - return "https://api.qrserver.com/v1/create-qr-code/?data=$urlencoded&size=${width}x${height}&ecc=$level"; }