/** * Generate provision URI according to KeyUriFormat * * @link https://code.google.com/p/google-authenticator/wiki/KeyUriFormat * @param string $label User label. * @param array $opts Additional URI parameters, e.g. ['image' => 'http://example.com/my_logo.png'] . * @throws \Bitrix\Main\ArgumentTypeException * @return string */ public function generateUri($label, array $opts = array()) { $positionalOpts = array('secret' => Base32::encode($this->getSecret())); $opts['algorithm'] = $this->getDigest(); // Digest must be in upper case for some OTP apps (e.g Google Authenticator for iOS) $opts['algorithm'] = strtoupper($opts['algorithm']); $opts['digits'] = $this->getDigits(); ksort($opts); // Some devices require a specific order for some parameters (e.g. Microsoft Authenticator require "secret" at first place %) ) $opts = array_merge($positionalOpts, $opts); $params = http_build_query($opts, '', '&'); // Ugly hack for old PHP versions. Use PHP_QUERY_RFC3986 when Bitrix reached PHP 5.4.0 $params = str_replace(array('+', '%7E'), array('%20', '~'), $params); return sprintf('%s://%s/%s?%s', $this->getAppScheme(), $this->getType(), rawurlencode($label), $params); }
/** * Set new mobile application secret * * @param string $value Secret. * @return $this */ public function setAppSecret($value) { $secret = Base32::decode($value); return $this->setSecret($secret); }