Passed
Push — master ( e63be5...345a82 )
by Greg
02:29
created

Auth0::errorCheck()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace GJClasses;
3
4
use Auth0\SDK\Auth0 as Auth0SDK;
5
6
class Auth0
7
{
8
    public $auth0;
9
10
    public function __construct()
11
    {
12
        $this->auth0 = new Auth0SDK([
13
            'domain' => GJC_AUTH0_DOMAIN,
14
            'client_id' => GJC_AUTH0_CLIENT_ID,
15
            'client_secret' => GJC_AUTH0_CLIENT_SECRET,
16
            'redirect_uri' => GJC_AUTH0_CALLBACK_URL,
17
            'audience' => GJC_AUTH0_AUDIENCE,
18
            'scope' => GJC_AUTH0_SCOPE,
19
            'persist_id_token' => GJC_AUTH0_PER_ID_TOKEN,
20
            'persist_access_token' => GJC_AUTH0_PER_ACCESS_TOKEN,
21
            'persist_refresh_token' => GJC_AUTH0_PER_REFRESH_TOKEN,
22
        ]);
23
    }
24
25
    public function check()
26
    {
27
        $user_info = $this->auth0->getUser();
28
29
        if (!$user_info) {
30
31
            header("Location: " . GJC_AUTH0_LOGIN_URL);
32
            exit;
33
34
        } else {
35
36
            return $user_info;
37
38
        }
39
40
    }
41
42
    public function errorCheck($error, $message)
43
    {
44
        if (isset($error) && $error != '') {
45
            echo 'Error: ' . $message;
46
            exit;
47
        }
48
        return;
49
    }
50
51
    public function login()
52
    {
53
        $this->auth0->login();
54
    }
55
56
    public function getUser()
57
    {
58
        return $this->auth0->getUser();
59
    }
60
61
    public function logout()
62
    {
63
        $this->auth0->logout();
64
        $logout_url = sprintf('http://%s/v2/logout?client_id=%s&returnTo=%s', GJC_AUTH0_DOMAIN, GJC_AUTH0_CLIENT_ID, GJC_AUTH0_LOGIN_URL);
65
        header('Location: ' . $logout_url);
66
        exit;
67
    }
68
69
}
70