Passed
Push — dev ( a738f4...ece0e3 )
by Greg
03:31
created

Auth0::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
rs 9.9332
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;
37
38
        }
39
40
    }
41
42
    public function login()
43
    {
44
        $this->auth0->login();
45
    }
46
47
    public function getUser()
48
    {
49
        return $this->auth0->getUser();
50
    }
51
52
    public function logout()
53
    {
54
        $this->auth0->logout();
55
        $logout_url = sprintf('http://%s/v2/logout?client_id=%s&returnTo=%s', GJC_AUTH0_DOMAIN, GJC_AUTH0_CLIENT_ID, GJC_AUTH0_LOGIN_URL);
56
        header('Location: ' . $logout_url);
57
        exit;
58
    }
59
60
}
61