@@ -34,7 +34,6 @@ class Authenticator{
3434
3535 protected SettingsContainerInterface |AuthenticatorOptions $ options ;
3636 protected AuthenticatorInterface $ authenticator ;
37- protected string $ mode = AuthenticatorInterface::TOTP ;
3837
3938 /**
4039 * Authenticator constructor
@@ -62,8 +61,7 @@ public function setOptions(SettingsContainerInterface|AuthenticatorOptions $opti
6261 $ this ->options = $ options ;
6362
6463 // invoke a new authenticator interface if necessary
65- if (!isset ($ this ->authenticator ) || $ this ->options ->mode !== $ this ->mode ){
66- $ this ->mode = $ this ->options ->mode ;
64+ if (!isset ($ this ->authenticator ) || $ this ->authenticator ::MODE !== $ this ->options ->mode ){
6765 $ this ->authenticator = new (AuthenticatorInterface::MODES [$ this ->options ->mode ])($ this ->options );
6866 }
6967
@@ -150,28 +148,31 @@ public function getUri(string $label, string $issuer, int|null $hotpCounter = nu
150148 'issuer ' => $ issuer ,
151149 ];
152150
153- if (($ omitSettings ?? $ this ->options ->omitUriSettings ) !== true ){
154- $ values ['digits ' ] = $ this ->options ->digits ;
155- $ values ['algorithm ' ] = $ this ->options ->algorithm ;
151+ if ($ this ->authenticator ::MODE === AuthenticatorInterface::HOTP ){
156152
157- if ($ this -> mode === AuthenticatorInterface:: TOTP ){
158- $ values [ ' period ' ] = $ this -> options -> period ;
153+ if ($ hotpCounter === null || $ hotpCounter < 0 ){
154+ throw new InvalidArgumentException ( ' initial counter value must be set and greater or equal to 0 ' ) ;
159155 }
160156
157+ $ values ['counter ' ] = $ hotpCounter ;
161158 }
162159
163- if ($ this ->mode === AuthenticatorInterface::HOTP ){
160+ if (($ omitSettings ?? $ this ->options ->omitUriSettings ) !== true ){
161+ $ values ['digits ' ] = $ this ->options ->digits ;
162+ $ values ['algorithm ' ] = $ this ->options ->algorithm ;
164163
165- if ($ hotpCounter === null || $ hotpCounter < 0 ){
166- throw new InvalidArgumentException ( ' initial counter value must be set and greater or equal to 0 ' ) ;
164+ if ($ this -> authenticator :: MODE === AuthenticatorInterface:: TOTP ){
165+ $ values [ ' period ' ] = $ this -> options -> period ;
167166 }
168167
169- $ values ['counter ' ] = $ hotpCounter ;
170168 }
171169
172- $ values = http_build_query ($ values , '' , '& ' , PHP_QUERY_RFC3986 );
173-
174- return sprintf ('otpauth://%s/%s?%s ' , $ this ->mode , rawurlencode ($ label ), $ values );
170+ return sprintf (
171+ 'otpauth://%s/%s?%s ' ,
172+ $ this ->authenticator ::MODE ,
173+ rawurlencode ($ label ),
174+ http_build_query ($ values , '' , '& ' , PHP_QUERY_RFC3986 ),
175+ );
175176 }
176177
177178}
0 commit comments