Auth0   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A login() 0 3 1
A errorCheck() 0 7 3
A check() 0 12 2
A logout() 0 6 1
A getUser() 0 3 1
A __construct() 0 12 1
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