This repository has been archived by the owner on Apr 18, 2019. It is now read-only.
/
CustomSessionStore.inc
102 lines (95 loc) · 2.43 KB
/
CustomSessionStore.inc
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
96
97
98
99
100
101
102
<?php
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
class CustomSessionStore{
function CustomSessionStore(){}
/**
* Indicates if the session store has a request token.
*
* @return True if a request token is present, false otherwise.
*/
function hasRequestToken(){
if($_COOKIE["yosRequestToken"]){
return true;
}else{
return false;
}
}
/**
* Indicates if the session store has an access token.
*
* @return True if an access token is present, false otherwise.
*/
function hasAccessToken(){
if($_COOKIE["yosAccessToken"] || $_POST['token']){
return true;
}else{
return false;
}
}
/**
* Stores the given request token in the session store.
*
* @param $token A PHP stdclass object containing the components of
* the OAuth request token.
* @return True on success, false otherwise.
*/
function storeRequestToken($token){
if (setcookie("yosRequestToken", serialize($token), time()+3600)){
return true;
}else{
return false;
}
}
/**
* Fetches and returns the request token from the session store.
*
* @return The request token.
*/
function fetchRequestToken(){
$contents = $_COOKIE["yosRequestToken"];
return unserialize(stripslashes($contents));
}
/**
* Clears the request token from the session store.
*
* @return True on success, false otherwise.
*/
function clearRequestToken(){
setcookie("yosRequestToken", "", time()-3600);
}
/**
* Stores the given access token in the session store.
*
* @param $token A PHP stdclass object containing the components of
* the OAuth access token.
* @return True on success, false otherwise.
*/
function storeAccessToken($token){
if(setcookie("yosAccessToken", serialize($token), time()+3600)){
return true;
}else{
return false;
}
}
/**
* Fetches and returns the access token from the session store.
*
* @return The access token.
*/
function fetchAccessToken(){
$contents = ($_COOKIE["yosAccessToken"]) ? $_COOKIE["yosAccessToken"] : $_POST['token'];
return unserialize(stripslashes($contents));
}
/**
* Clears the access token from the session store.
*
* @return True on success, false otherwise.
*/
function clearAccessToken(){
setcookie("yosAccessToken", "", time()-3600);
}
}
?>