Skip to content

Commit 682e0e4

Browse files
Added Google Authentication
1 parent 48294a1 commit 682e0e4

16 files changed

+210
-3
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ APP_URL=http://localhost
77
OPUS_MAIL_SENDER_ADDRESS=you@domain.com
88
OPUS_MAIL_SENDER_NAME=you@domain.com
99
OPUS_TEAM_NAME=yourTeamName
10+
OPUS_TEAM_DOMAIN=yourDomain.co.uk
1011

1112
DB_CONNECTION=mysql
1213
DB_HOST=mysql
@@ -34,3 +35,7 @@ MAIL_ENCRYPTION=null
3435
PUSHER_APP_ID=
3536
PUSHER_KEY=
3637
PUSHER_SECRET=
38+
39+
GOOGLE_CLIENT_ID=
40+
GOOGLE_CLIENT_SECRET=
41+
GOOGLE_REDIRECT=
6 Bytes
Binary file not shown.
519 Bytes
Binary file not shown.
386 Bytes
Binary file not shown.
6 Bytes
Binary file not shown.
6 Bytes
Binary file not shown.

.phpintel/index

69 Bytes
Binary file not shown.

app/Http/Controllers/UserController.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Image;
99
use Mail;
1010
use Session;
11+
use Socialite;
1112
use App\Models\User;
1213
use App\Models\Wiki;
1314
use App\Models\Team;
@@ -403,4 +404,50 @@ public function findUser($passwordReset)
403404
{
404405
return $this->team->getUser($passwordReset);
405406
}
407+
408+
/**
409+
* Redirect the user to the Google authentication page.
410+
*
411+
* @return \Illuminate\Http\Response
412+
*/
413+
public function redirectToProvider()
414+
{
415+
return Socialite::driver('google')->redirect();
416+
}
417+
418+
/**
419+
* Obtain the user information from Google.
420+
*
421+
* @return \Illuminate\Http\Response
422+
*/
423+
public function handleProviderCallback()
424+
{
425+
try {
426+
$user = Socialite::driver('google')->user();
427+
} catch (\Exception $e) {
428+
\Log::error($e->getMessage());
429+
return redirect('/login')->with([
430+
'alert' => 'Google authentication error!',
431+
]);
432+
}
433+
// only allow people in the configured domain to login
434+
if(explode("@", $user->email)[1] !== config('opus.team_domain')){
435+
return redirect()->to('/')->with([
436+
'alert' => 'You must have already been invited to log in with Google.',
437+
]);
438+
}
439+
// check if they're an existing user
440+
$existingUser = User::where('email', $user->email)->first();
441+
442+
if($existingUser){
443+
// log them in
444+
auth()->login($existingUser, true);
445+
} else {
446+
return redirect()->back()->with([
447+
'alert' => 'You must have already been invited to log in with Google.',
448+
]);
449+
}
450+
451+
return redirect()->to('/home');
452+
}
406453
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"guzzlehttp/guzzle": "~5.3|~6.0",
3838
"intervention/image": "^2.3",
3939
"laravel/framework": "5.8.*",
40+
"laravel/socialite": "^4.3",
4041
"laravel/telescope": "^2.0",
4142
"laravel/tinker": "^1.0",
4243
"sentry/sentry-laravel": "^1.0"

composer.lock

Lines changed: 132 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)