File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
app/Http/Controllers/WebAuthn Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,15 @@ class WebAuthnLoginController
2727 */
2828 public function options (AssertionRequest $ request ): Responsable
2929 {
30- return $ request ->toVerify ($ request ->validate (['user_id ' => 'sometimes|int ' ])['user_id ' ] ?? null );
30+ $ fields = $ request ->validate ([
31+ 'user_id ' => 'sometimes|int ' ,
32+ 'username ' => 'sometimes|string ' ,
33+ ]);
34+
35+ $ username = $ fields ['username ' ] ?? null ;
36+ $ authenticatable = $ fields ['user_id ' ] ?? ($ username !== null ? ['username ' => $ username ] : null );
37+
38+ return $ request ->toVerify ($ authenticatable );
3139 }
3240
3341 /**
Original file line number Diff line number Diff line change @@ -211,6 +211,34 @@ public function testWebAuthLoginOptions(): void
211211 ]);
212212 }
213213
214+ /**
215+ * Testing the Login options.
216+ *
217+ * @return void
218+ */
219+ public function testWebAuthLoginOptionsUsername (): void
220+ {
221+ $ this ->createCredentials ();
222+
223+ // Generate a challenge for username = admin
224+ $ response = $ this ->postJson ('/api/WebAuthn::login/options ' , ['username ' => 'admin ' ]);
225+ $ this ->assertOk ($ response );
226+
227+ $ challengeRetrieved = Session::get (config ('webauthn.challenge.key ' ));
228+ $ clg = $ challengeRetrieved ->data ->toBase64Url ();
229+
230+ $ response ->assertJson ([
231+ 'timeout ' => 60000 ,
232+ 'challenge ' => $ clg ,
233+ 'allowCredentials ' => [
234+ 0 => [
235+ 'id ' => '_Xlz-khgFhDdkvOWyy_YqC54ExkYyp1o6HAQiybqLST-9RGBndpgI06TQygIYI7ZL2dayCMYm6J1-bXyl72obA ' ,
236+ 'type ' => 'public-key ' ,
237+ ],
238+ ],
239+ ]);
240+ }
241+
214242 /**
215243 * Testing the Login interface.
216244 *
You can’t perform that action at this time.
0 commit comments