SocialiteController::redirectToProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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