@@ -77,13 +77,21 @@ class DuoSecurity implements EngineInterface
77
77
*/
78
78
private $ scopeConfig ;
79
79
80
+ /**
81
+ * @var bool
82
+ */
83
+ private $ forceUseDuoAuth ;
84
+
80
85
/**
81
86
* @param ScopeConfigInterface $scopeConfig
87
+ * @param bool $forceUseDuoAuth
82
88
*/
83
89
public function __construct (
84
- ScopeConfigInterface $ scopeConfig
90
+ ScopeConfigInterface $ scopeConfig ,
91
+ bool $ forceUseDuoAuth = false
85
92
) {
86
93
$ this ->scopeConfig = $ scopeConfig ;
94
+ $ this ->forceUseDuoAuth = $ forceUseDuoAuth ;
87
95
}
88
96
89
97
/**
@@ -208,7 +216,7 @@ public function getRequestSignature(UserInterface $user): string
208
216
$ duoSignature = $ this ->signValues (
209
217
$ this ->getSecretKey (),
210
218
$ values ,
211
- static :: DUO_PREFIX ,
219
+ $ this -> getPrefix () ,
212
220
static ::DUO_EXPIRE ,
213
221
$ time
214
222
);
@@ -223,6 +231,16 @@ public function getRequestSignature(UserInterface $user): string
223
231
return $ duoSignature . ': ' . $ appSignature ;
224
232
}
225
233
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
+
226
244
/**
227
245
* @inheritDoc
228
246
*/
@@ -236,8 +254,8 @@ public function verify(UserInterface $user, DataObject $request): bool
236
254
}
237
255
[$ authSig , $ appSig ] = $ signatures ;
238
256
257
+ $ authUser = $ this ->parseValues ($ this ->getSecretKey (), $ authSig , static ::AUTH_PREFIX , $ time );
239
258
$ appUser = $ this ->parseValues ($ this ->getApplicationKey (), $ appSig , static ::APP_PREFIX , $ time );
240
- $ authUser = $ this ->parseValues ($ this ->getSecretKey (), $ authSig , static ::DUO_PREFIX , $ time );
241
259
242
260
return (($ authUser === $ appUser ) && ($ appUser === $ user ->getUserName ()));
243
261
}
0 commit comments