@@ -129,17 +129,19 @@ public function __construct(
129129 $ this ->encryptor = $ encryptor ;
130130 $ this ->urlBuilder = $ urlBuilder ;
131131 $ this ->formKey = $ formKey ;
132- $ this ->client = $ client ?? new Client (
133- $ this ->getClientId (),
134- $ this ->getClientSecret (),
135- $ this ->getApiHostname (),
136- $ this ->getCallbackUrl ()
137- );
138- $ this ->duoAuth = $ duoAuth ?? new DuoAuth (
139- $ this ->getIkey (),
140- $ this ->getSkey (),
141- $ this ->getApiHostname ()
142- );
132+ if ($ this ->isDuoForcedProvider ()) {
133+ $ this ->client = $ client ?? new Client (
134+ $ this ->getClientId (),
135+ $ this ->getClientSecret (),
136+ $ this ->getApiHostname (),
137+ $ this ->getCallbackUrl ()
138+ );
139+ $ this ->duoAuth = $ duoAuth ?? new DuoAuth (
140+ $ this ->getIkey (),
141+ $ this ->getSkey (),
142+ $ this ->getApiHostname ()
143+ );
144+ }
143145 }
144146
145147 /**
@@ -149,7 +151,7 @@ public function __construct(
149151 */
150152 public function getApiHostname (): string
151153 {
152- return $ this ->scopeConfig ->getValue (static ::XML_PATH_API_HOSTNAME ) ?: ' test.duosecurity.com ' ;
154+ return $ this ->scopeConfig ->getValue (static ::XML_PATH_API_HOSTNAME );
153155 }
154156
155157 /**
@@ -162,7 +164,7 @@ private function getClientSecret(): string
162164 // return default value if client secret is not set as per Duo Library
163165 return $ this ->encryptor ->decrypt (
164166 $ this ->scopeConfig ->getValue (static ::XML_PATH_CLIENT_SECRET )
165- ) ?: ' abcdefghijklmnopqrstuvwxyzabcdefghij1234567890 ' ;
167+ );
166168 }
167169
168170 /**
@@ -173,7 +175,7 @@ private function getClientSecret(): string
173175 private function getClientId (): string
174176 {
175177 // return default value if client id is not set as per Duo Library
176- return $ this ->scopeConfig ->getValue (static ::XML_PATH_CLIENT_ID ) ?: ' ABCDEFGHIJKLMNOPQRST ' ;
178+ return $ this ->scopeConfig ->getValue (static ::XML_PATH_CLIENT_ID );
177179 }
178180
179181 /**
@@ -203,7 +205,7 @@ private function getCallbackUrl(): string
203205 */
204206 private function getIkey (): string
205207 {
206- return $ this ->scopeConfig ->getValue (static ::XML_PATH_IKEY ) ?: ' DIXXXXXXXXX ' ;
208+ return $ this ->scopeConfig ->getValue (static ::XML_PATH_IKEY );
207209 }
208210
209211 /**
@@ -213,7 +215,7 @@ private function getIkey(): string
213215 */
214216 private function getSkey (): string
215217 {
216- return $ this ->scopeConfig ->getValue (static ::XML_PATH_SKEY ) ?: ' abcdefghijklmnopqrstuvwxyzabcdefghij1234567890 ' ;
218+ return $ this ->scopeConfig ->getValue (static ::XML_PATH_SKEY );
217219 }
218220
219221 /**
@@ -242,13 +244,21 @@ public function verify(UserInterface $user, DataObject $request): bool
242244 return true ;
243245 }
244246
247+ private function isDuoForcedProvider (): bool
248+ {
249+ $ providers = $ this ->scopeConfig ->getValue ('twofactorauth/general/force_providers ' ) ?? '' ;
250+ $ forcedProviders = array_map ('trim ' , explode (', ' , $ providers ));
251+ return in_array (self ::CODE , $ forcedProviders , true );
252+ }
253+
245254 /**
246255 * @inheritDoc
247256 */
248257 public function isEnabled (): bool
249258 {
250259 try {
251- return !!$ this ->getApiHostname () &&
260+ return $ this ->isDuoForcedProvider () &&
261+ !!$ this ->getApiHostname () &&
252262 !!$ this ->getClientId () &&
253263 !!$ this ->getClientSecret ();
254264 } catch (\TypeError $ exception ) {
0 commit comments