@@ -77,13 +77,21 @@ class DuoSecurity implements EngineInterface
7777 */
7878 private $ scopeConfig ;
7979
80+ /**
81+ * @var bool
82+ */
83+ private $ forceUseDuoAuth ;
84+
8085 /**
8186 * @param ScopeConfigInterface $scopeConfig
87+ * @param bool $forceUseDuoAuth
8288 */
8389 public function __construct (
84- ScopeConfigInterface $ scopeConfig
90+ ScopeConfigInterface $ scopeConfig ,
91+ bool $ forceUseDuoAuth = false
8592 ) {
8693 $ this ->scopeConfig = $ scopeConfig ;
94+ $ this ->forceUseDuoAuth = $ forceUseDuoAuth ;
8795 }
8896
8997 /**
@@ -208,7 +216,7 @@ public function getRequestSignature(UserInterface $user): string
208216 $ duoSignature = $ this ->signValues (
209217 $ this ->getSecretKey (),
210218 $ values ,
211- static :: DUO_PREFIX ,
219+ $ this -> getPrefix () ,
212220 static ::DUO_EXPIRE ,
213221 $ time
214222 );
@@ -223,6 +231,16 @@ public function getRequestSignature(UserInterface $user): string
223231 return $ duoSignature . ': ' . $ appSignature ;
224232 }
225233
234+ /**
235+ * Return prefix to use in the signature
236+ *
237+ * @return string
238+ */
239+ private function getPrefix () : string
240+ {
241+ return ($ this ->forceUseDuoAuth ) ? static ::DUO_PREFIX : static ::AUTH_PREFIX ;
242+ }
243+
226244 /**
227245 * @inheritDoc
228246 */
@@ -236,8 +254,8 @@ public function verify(UserInterface $user, DataObject $request): bool
236254 }
237255 [$ authSig , $ appSig ] = $ signatures ;
238256
257+ $ authUser = $ this ->parseValues ($ this ->getSecretKey (), $ authSig , static ::AUTH_PREFIX , $ time );
239258 $ appUser = $ this ->parseValues ($ this ->getApplicationKey (), $ appSig , static ::APP_PREFIX , $ time );
240- $ authUser = $ this ->parseValues ($ this ->getSecretKey (), $ authSig , static ::DUO_PREFIX , $ time );
241259
242260 return (($ authUser === $ appUser ) && ($ appUser === $ user ->getUserName ()));
243261 }
0 commit comments