-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.php
More file actions
95 lines (75 loc) · 1.95 KB
/
Copy pathSession.php
File metadata and controls
95 lines (75 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace OnePlusOne\OAuthBundle;
use Symfony\Component\HttpFoundation\Session as HttpSession;
use OnePlusOne\OAuthBundle\Services\Service;
class Session
{
protected $session;
protected $services = array();
public function __construct(HttpSession $session)
{
$this->session = $session;
}
public function addService(Service $service)
{
$this->services[$service->getAlias()] = $service;
}
public function isAuthenticated()
{
return $this->session->has('oauth_bundle/authenticated');
}
public function getUser()
{
if($this->session->has('oauth_bundle/user'))
return $this->session->get('oauth_bundle/user');
else
return null;
}
public function getService($service)
{
if(!isset($this->services[$service]))
throw new \InvalidArgumentException(sprintf('No service found with name "%s"', $service));
return $this->services[$service];
}
public function hasService($service)
{
return isset($this->services[$service]);
}
public function getServiceName()
{
if($this->session->has('oauth_bundle/service'))
return $this->session->get('oauth_bundle/service');
else
return null;
}
public function getLoginUrl($service, $succesUrl, $failureUrl)
{
return $this->getService($service)->getLoginUrl($succesUrl, $failureUrl);
}
public function getLogoutUrl($service, $succesUrl)
{
return $this->getService($service)->getLogoutUrl($succesUrl);
}
public function verifyCallback($service)
{
try
{
$user = $this->getService($service)->getUser();
$this->session->set('oauth_bundle/user', $user);
$this->session->set('oauth_bundle/authenticated', true);
$this->session->set('oauth_bundle/service', $service);
return true;
}
catch (\Exception $e)
{
return false;
}
}
public function logout()
{
$this->session->remove('oauth_bundle/user');
$this->session->remove('oauth_bundle/authenticated');
$this->session->remove('oauth_bundle/service');
return true;
}
}