|
13 | 13 |
|
14 | 14 | use chillerlan\Authenticator\Authenticators\AuthenticatorInterface; |
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | | -use InvalidArgumentException; |
17 | 16 | use SensitiveParameter; |
18 | | -use function http_build_query; |
19 | | -use function rawurlencode; |
20 | | -use function sprintf; |
21 | | -use function trim; |
22 | | -use const PHP_QUERY_RFC3986; |
23 | 17 |
|
24 | 18 | /** |
25 | 19 | * Yet another Google authenticator implementation! |
@@ -133,46 +127,16 @@ public function verify(#[SensitiveParameter] string $otp, int|null $data = null) |
133 | 127 | * @deprecated 5.3.0 The parameter `$omitSettings` will be removed in favor of `AuthenticatorOptions::$omitUriSettings` |
134 | 128 | * in the next major version (6.x) |
135 | 129 | * @see \chillerlan\Authenticator\AuthenticatorOptionsTrait::$omitUriSettings |
136 | | - * @throws \InvalidArgumentException |
| 130 | + * |
| 131 | + * @codeCoverageIgnore |
137 | 132 | */ |
138 | 133 | public function getUri(string $label, string $issuer, int|null $hotpCounter = null, bool|null $omitSettings = null):string{ |
139 | | - $label = trim($label); |
140 | | - $issuer = trim($issuer); |
141 | | - |
142 | | - if(empty($label) || empty($issuer)){ |
143 | | - throw new InvalidArgumentException('$label and $issuer cannot be empty'); |
144 | | - } |
145 | | - |
146 | | - $values = [ |
147 | | - 'secret' => $this->authenticator->getSecret(), |
148 | | - 'issuer' => $issuer, |
149 | | - ]; |
150 | | - |
151 | | - if($this->authenticator::MODE === AuthenticatorInterface::HOTP){ |
152 | | - |
153 | | - if($hotpCounter === null || $hotpCounter < 0){ |
154 | | - throw new InvalidArgumentException('initial counter value must be set and greater or equal to 0'); |
155 | | - } |
156 | | - |
157 | | - $values['counter'] = $hotpCounter; |
158 | | - } |
159 | | - |
160 | | - if(($omitSettings ?? $this->options->omitUriSettings) !== true){ |
161 | | - $values['digits'] = $this->options->digits; |
162 | | - $values['algorithm'] = $this->options->algorithm; |
163 | | - |
164 | | - if($this->authenticator::MODE === AuthenticatorInterface::TOTP){ |
165 | | - $values['period'] = $this->options->period; |
166 | | - } |
167 | | - |
| 134 | + // a little reckless but good enough until the deprecated parameter is removed |
| 135 | + if($omitSettings !== null){ |
| 136 | + $this->options->omitUriSettings = $omitSettings; |
168 | 137 | } |
169 | 138 |
|
170 | | - return sprintf( |
171 | | - 'otpauth://%s/%s?%s', |
172 | | - $this->authenticator::MODE, |
173 | | - rawurlencode($label), |
174 | | - http_build_query($values, '', '&', PHP_QUERY_RFC3986), |
175 | | - ); |
| 139 | + return $this->authenticator->getUri($label, $issuer, $hotpCounter); |
176 | 140 | } |
177 | 141 |
|
178 | 142 | } |
0 commit comments