Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 102 lines (95 sloc) 2.484 kb
d4d101e @jcleblanc PHP OAuth flow with custom session store
jcleblanc authored
1 <?php
a58e5d8 added licensing
erik authored
2 /*
3 Copyright (c) 2009 Yahoo! Inc. All rights reserved.
4 The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
5 */
d4d101e @jcleblanc PHP OAuth flow with custom session store
jcleblanc authored
6 class CustomSessionStore{
7 function CustomSessionStore(){}
8 /**
9 * Indicates if the session store has a request token.
10 *
11 * @return True if a request token is present, false otherwise.
12 */
13 function hasRequestToken(){
14 if($_COOKIE["yosRequestToken"]){
15 return true;
16 }else{
17 return false;
18 }
19 }
20
21 /**
22 * Indicates if the session store has an access token.
23 *
24 * @return True if an access token is present, false otherwise.
25 */
26 function hasAccessToken(){
27 if($_COOKIE["yosAccessToken"] || $_POST['token']){
28 return true;
29 }else{
30 return false;
31 }
32 }
33
34 /**
35 * Stores the given request token in the session store.
36 *
37 * @param $token A PHP stdclass object containing the components of
38 * the OAuth request token.
39 * @return True on success, false otherwise.
40 */
41 function storeRequestToken($token){
42 if (setcookie("yosRequestToken", serialize($token), time()+3600)){
43 return true;
44 }else{
45 return false;
46 }
47 }
48
49 /**
50 * Fetches and returns the request token from the session store.
51 *
52 * @return The request token.
53 */
54 function fetchRequestToken(){
55 $contents = $_COOKIE["yosRequestToken"];
56 return unserialize(stripslashes($contents));
57 }
58
59 /**
60 * Clears the request token from the session store.
61 *
62 * @return True on success, false otherwise.
63 */
64 function clearRequestToken(){
65 setcookie("yosRequestToken", "", time()-3600);
66 }
67
68 /**
69 * Stores the given access token in the session store.
70 *
71 * @param $token A PHP stdclass object containing the components of
72 * the OAuth access token.
73 * @return True on success, false otherwise.
74 */
75 function storeAccessToken($token){
76 if(setcookie("yosAccessToken", serialize($token), time()+3600)){
77 return true;
78 }else{
79 return false;
80 }
81 }
82
83 /**
84 * Fetches and returns the access token from the session store.
85 *
86 * @return The access token.
87 */
88 function fetchAccessToken(){
89 $contents = ($_COOKIE["yosAccessToken"]) ? $_COOKIE["yosAccessToken"] : $_POST['token'];
90 return unserialize(stripslashes($contents));
91 }
92
93 /**
94 * Clears the access token from the session store.
95 *
96 * @return True on success, false otherwise.
97 */
98 function clearAccessToken(){
99 setcookie("yosAccessToken", "", time()-3600);
100 }
101 }
102 ?>
Something went wrong with that request. Please try again.