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