SocialiteController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A redirectToProvider() 0 4 1
A handleProviderCallback() 0 10 2
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