SocialiteController::handleProviderCallback()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace STS\SocialiteAuth\Http\Controllers;
4
5
use STS\SocialiteAuth\Facades\SocialiteAuth;
6
use Illuminate\Support\Facades\Auth;
7
use Laravel\Socialite\Facades\Socialite;
8
9
class SocialiteController
10
{
11
    /**
12
     * Redirect the user to the OAuth Provider.
13
     */
14
    public function redirectToProvider()
15
    {
16
        return SocialiteAuth::getDriver()->redirect();
17
    }
18
19
    /**
20
     * Obtain the user information from provider.  Check if the user already exists in our
21
     * database by looking up their provider_id in the database.
22
     * If the user exists, log them in. Otherwise, create a new user then log them in. After that
23
     * redirect them to the authenticated users homepage.
24
     */
25
    public function handleProviderCallback()
26
    {
27
        $user = Socialite::driver(config('socialite-auth.driver'))->user();
28
29
        if (Auth::guard('socialite')->attemptFromSocialite($user, config('socialite-auth.field'))) {
30
            return redirect()->intended();
31
        }
32
33
        abort(401);
34
    }
35
}
36