File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ public function callback(string $provider)
1919 {
2020 try {
2121 $ oauthUser = get_socialite_provider ($ provider )->user ();
22- $ email = strtolower (trim ((string ) $ oauthUser ->email ));
22+ $ email = trim ((string ) $ oauthUser ->email );
23+ if ($ email === '' ) {
24+ abort (403 , 'OAuth provider did not return an email address ' );
25+ }
26+ $ email = strtolower ($ email );
2327 $ user = User::whereEmail ($ email )->first ();
2428 if (! $ user ) {
2529 $ settings = instanceSettings ();
Original file line number Diff line number Diff line change 4747 $ this ->assertAuthenticatedAs ($ user );
4848 expect (User::count ())->toBe (1 );
4949});
50+
51+ it ('rejects oauth logins when the provider does not return an email address ' , function (?string $ providerEmail ) {
52+ config ()->set ('app.maintenance.driver ' , 'file ' );
53+ InstanceSettings::firstOrCreate ([
54+ 'id ' => 0 ,
55+ ], [
56+ 'is_registration_enabled ' => false ,
57+ ])->update ([
58+ 'is_registration_enabled ' => true ,
59+ ]);
60+
61+ $ provider = \Mockery::mock ();
62+ $ provider ->shouldReceive ('setConfig ' )->once ()->andReturnSelf ();
63+ $ provider ->shouldReceive ('with ' )->once ()->with (['hd ' => 'example.com ' ])->andReturnSelf ();
64+ $ provider ->shouldReceive ('user ' )->once ()->andReturn ((object ) [
65+ 'email ' => $ providerEmail ,
66+ 'name ' => 'Tristan Rhodes ' ,
67+ 'id ' => 'google-user-id ' ,
68+ ]);
69+
70+ Socialite::shouldReceive ('driver ' )->once ()->with ('google ' )->andReturn ($ provider );
71+
72+ $ response = $ this ->from ('/login ' )->get (route ('auth.callback ' , 'google ' ));
73+
74+ $ response ->assertRedirect ('/login ' );
75+ expect (User::count ())->toBe (0 );
76+ })->with ([
77+ 'null email ' => [null ],
78+ 'blank email ' => [' ' ],
79+ ]);
You can’t perform that action at this time.
0 commit comments