@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * This method returns the name of the directory where PGT's should be stored |
62 | 62 | * on the filesystem. |
63 | 63 | * |
64 | - * @return the name of a directory (with leading and trailing '/') |
|
64 | + * @return string name of a directory (with leading and trailing '/') |
|
65 | 65 | * |
66 | 66 | * @private |
67 | 67 | */ |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * This method returns the format to use when storing PGT's on the filesystem. |
83 | 83 | * |
84 | - * @return a string corresponding to the format used (plain or xml). |
|
84 | + * @return string string corresponding to the format used (plain or xml). |
|
85 | 85 | * |
86 | 86 | * @private |
87 | 87 | */ |
@@ -44,231 +44,231 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorageFile extends PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorageFile |
|
49 | - * @{ |
|
50 | - */ |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorageFile |
|
49 | + * @{ |
|
50 | + */ |
|
51 | 51 | |
52 | - /** |
|
53 | - * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | - * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | - * |
|
56 | - * @private |
|
57 | - */ |
|
58 | - var $_path; |
|
52 | + /** |
|
53 | + * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | + * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | + * |
|
56 | + * @private |
|
57 | + */ |
|
58 | + var $_path; |
|
59 | 59 | |
60 | - /** |
|
61 | - * This method returns the name of the directory where PGT's should be stored |
|
62 | - * on the filesystem. |
|
63 | - * |
|
64 | - * @return the name of a directory (with leading and trailing '/') |
|
65 | - * |
|
66 | - * @private |
|
67 | - */ |
|
68 | - function getPath() |
|
60 | + /** |
|
61 | + * This method returns the name of the directory where PGT's should be stored |
|
62 | + * on the filesystem. |
|
63 | + * |
|
64 | + * @return the name of a directory (with leading and trailing '/') |
|
65 | + * |
|
66 | + * @private |
|
67 | + */ |
|
68 | + function getPath() |
|
69 | 69 | { |
70 | - return $this->_path; |
|
70 | + return $this->_path; |
|
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | - * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | - * |
|
77 | - * @private |
|
78 | - */ |
|
79 | - var $_format; |
|
73 | + /** |
|
74 | + * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | + * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | + * |
|
77 | + * @private |
|
78 | + */ |
|
79 | + var $_format; |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | - * |
|
84 | - * @return a string corresponding to the format used (plain or xml). |
|
85 | - * |
|
86 | - * @private |
|
87 | - */ |
|
88 | - function getFormat() |
|
81 | + /** |
|
82 | + * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | + * |
|
84 | + * @return a string corresponding to the format used (plain or xml). |
|
85 | + * |
|
86 | + * @private |
|
87 | + */ |
|
88 | + function getFormat() |
|
89 | 89 | { |
90 | - return $this->_format; |
|
90 | + return $this->_format; |
|
91 | 91 | } |
92 | 92 | |
93 | - // ######################################################################## |
|
94 | - // DEBUGGING |
|
95 | - // ######################################################################## |
|
93 | + // ######################################################################## |
|
94 | + // DEBUGGING |
|
95 | + // ######################################################################## |
|
96 | 96 | |
97 | - /** |
|
98 | - * This method returns an informational string giving the type of storage |
|
99 | - * used by the object (used for debugging purposes). |
|
100 | - * |
|
101 | - * @return string informational string. |
|
102 | - * @public |
|
103 | - */ |
|
104 | - function getStorageType() |
|
97 | + /** |
|
98 | + * This method returns an informational string giving the type of storage |
|
99 | + * used by the object (used for debugging purposes). |
|
100 | + * |
|
101 | + * @return string informational string. |
|
102 | + * @public |
|
103 | + */ |
|
104 | + function getStorageType() |
|
105 | 105 | { |
106 | - return "file"; |
|
106 | + return "file"; |
|
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * This method returns an informational string giving informations on the |
|
111 | - * parameters of the storage.(used for debugging purposes). |
|
112 | - * |
|
113 | - * @return string informational string. |
|
114 | - * @public |
|
115 | - */ |
|
116 | - function getStorageInfo() |
|
109 | + /** |
|
110 | + * This method returns an informational string giving informations on the |
|
111 | + * parameters of the storage.(used for debugging purposes). |
|
112 | + * |
|
113 | + * @return string informational string. |
|
114 | + * @public |
|
115 | + */ |
|
116 | + function getStorageInfo() |
|
117 | 117 | { |
118 | - return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
118 | + return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
119 | 119 | } |
120 | 120 | |
121 | - // ######################################################################## |
|
122 | - // CONSTRUCTOR |
|
123 | - // ######################################################################## |
|
121 | + // ######################################################################## |
|
122 | + // CONSTRUCTOR |
|
123 | + // ######################################################################## |
|
124 | 124 | |
125 | - /** |
|
126 | - * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | - * |
|
128 | - * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
129 | - * @param string $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | - * @param string $path the path where the PGT's should be stored |
|
131 | - * |
|
132 | - * @public |
|
133 | - */ |
|
134 | - function PGTStorageFile($cas_parent,$format,$path) |
|
125 | + /** |
|
126 | + * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | + * |
|
128 | + * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
129 | + * @param string $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | + * @param string $path the path where the PGT's should be stored |
|
131 | + * |
|
132 | + * @public |
|
133 | + */ |
|
134 | + function PGTStorageFile($cas_parent,$format,$path) |
|
135 | 135 | { |
136 | - phpCAS::traceBegin(); |
|
137 | - // call the ancestor's constructor |
|
138 | - $this->PGTStorage($cas_parent); |
|
136 | + phpCAS::traceBegin(); |
|
137 | + // call the ancestor's constructor |
|
138 | + $this->PGTStorage($cas_parent); |
|
139 | 139 | |
140 | - if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | - if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
140 | + if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | + if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
142 | 142 | |
143 | - // check that the path is an absolute path |
|
144 | - if (getenv("OS")=="Windows_NT"){ |
|
143 | + // check that the path is an absolute path |
|
144 | + if (getenv("OS")=="Windows_NT"){ |
|
145 | 145 | |
146 | - if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | - } |
|
146 | + if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | + } |
|
149 | 149 | |
150 | - } |
|
151 | - else |
|
152 | - { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
153 | 153 | |
154 | - if ( $path[0] != '/' ) { |
|
155 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | - } |
|
154 | + if ( $path[0] != '/' ) { |
|
155 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | + } |
|
157 | 157 | |
158 | - // store the path (with a leading and trailing '/') |
|
159 | - $path = preg_replace('|[/]*$|','/',$path); |
|
160 | - $path = preg_replace('|^[/]*|','/',$path); |
|
161 | - } |
|
158 | + // store the path (with a leading and trailing '/') |
|
159 | + $path = preg_replace('|[/]*$|','/',$path); |
|
160 | + $path = preg_replace('|^[/]*|','/',$path); |
|
161 | + } |
|
162 | 162 | |
163 | - $this->_path = $path; |
|
164 | - // check the format and store it |
|
165 | - switch ($format) { |
|
166 | - case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
163 | + $this->_path = $path; |
|
164 | + // check the format and store it |
|
165 | + switch ($format) { |
|
166 | + case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
167 | 167 | case CAS_PGT_STORAGE_FILE_FORMAT_XML: |
168 | - $this->_format = $format; |
|
169 | - break; |
|
170 | - default: |
|
171 | - phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | - } |
|
173 | - phpCAS::traceEnd(); |
|
168 | + $this->_format = $format; |
|
169 | + break; |
|
170 | + default: |
|
171 | + phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | + } |
|
173 | + phpCAS::traceEnd(); |
|
174 | 174 | } |
175 | 175 | |
176 | - // ######################################################################## |
|
177 | - // INITIALIZATION |
|
178 | - // ######################################################################## |
|
176 | + // ######################################################################## |
|
177 | + // INITIALIZATION |
|
178 | + // ######################################################################## |
|
179 | 179 | |
180 | - /** |
|
181 | - * This method is used to initialize the storage. Halts on error. |
|
182 | - * |
|
183 | - * @public |
|
184 | - */ |
|
185 | - function init() |
|
180 | + /** |
|
181 | + * This method is used to initialize the storage. Halts on error. |
|
182 | + * |
|
183 | + * @public |
|
184 | + */ |
|
185 | + function init() |
|
186 | 186 | { |
187 | - phpCAS::traceBegin(); |
|
188 | - // if the storage has already been initialized, return immediatly |
|
189 | - if ( $this->isInitialized() ) |
|
190 | - return; |
|
191 | - // call the ancestor's method (mark as initialized) |
|
192 | - parent::init(); |
|
193 | - phpCAS::traceEnd(); |
|
187 | + phpCAS::traceBegin(); |
|
188 | + // if the storage has already been initialized, return immediatly |
|
189 | + if ( $this->isInitialized() ) |
|
190 | + return; |
|
191 | + // call the ancestor's method (mark as initialized) |
|
192 | + parent::init(); |
|
193 | + phpCAS::traceEnd(); |
|
194 | 194 | } |
195 | 195 | |
196 | - // ######################################################################## |
|
197 | - // PGT I/O |
|
198 | - // ######################################################################## |
|
196 | + // ######################################################################## |
|
197 | + // PGT I/O |
|
198 | + // ######################################################################## |
|
199 | 199 | |
200 | - /** |
|
201 | - * This method returns the filename corresponding to a PGT Iou. |
|
202 | - * |
|
203 | - * @param $pgt_iou the PGT iou. |
|
204 | - * |
|
205 | - * @return string filename |
|
206 | - * @private |
|
207 | - */ |
|
208 | - function getPGTIouFilename($pgt_iou) |
|
200 | + /** |
|
201 | + * This method returns the filename corresponding to a PGT Iou. |
|
202 | + * |
|
203 | + * @param $pgt_iou the PGT iou. |
|
204 | + * |
|
205 | + * @return string filename |
|
206 | + * @private |
|
207 | + */ |
|
208 | + function getPGTIouFilename($pgt_iou) |
|
209 | 209 | { |
210 | - phpCAS::traceBegin(); |
|
211 | - $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | - phpCAS::traceEnd($filename); |
|
213 | - return $filename; |
|
210 | + phpCAS::traceBegin(); |
|
211 | + $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | + phpCAS::traceEnd($filename); |
|
213 | + return $filename; |
|
214 | 214 | } |
215 | 215 | |
216 | - /** |
|
217 | - * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | - * warning on error. |
|
219 | - * |
|
220 | - * @param $pgt the PGT |
|
221 | - * @param $pgt_iou the PGT iou |
|
222 | - * |
|
223 | - * @public |
|
224 | - */ |
|
225 | - function write($pgt,$pgt_iou) |
|
216 | + /** |
|
217 | + * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | + * warning on error. |
|
219 | + * |
|
220 | + * @param $pgt the PGT |
|
221 | + * @param $pgt_iou the PGT iou |
|
222 | + * |
|
223 | + * @public |
|
224 | + */ |
|
225 | + function write($pgt,$pgt_iou) |
|
226 | 226 | { |
227 | - phpCAS::traceBegin(); |
|
228 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | - if ( $f=fopen($fname,"w") ) { |
|
230 | - if ( fputs($f,$pgt) === FALSE ) { |
|
231 | - phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | - } |
|
233 | - fclose($f); |
|
234 | - } else { |
|
235 | - phpCAS::error('could not open `'.$fname.'\''); |
|
236 | - } |
|
237 | - phpCAS::traceEnd(); |
|
227 | + phpCAS::traceBegin(); |
|
228 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | + if ( $f=fopen($fname,"w") ) { |
|
230 | + if ( fputs($f,$pgt) === FALSE ) { |
|
231 | + phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | + } |
|
233 | + fclose($f); |
|
234 | + } else { |
|
235 | + phpCAS::error('could not open `'.$fname.'\''); |
|
236 | + } |
|
237 | + phpCAS::traceEnd(); |
|
238 | 238 | } |
239 | 239 | |
240 | - /** |
|
241 | - * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | - * corresponding file. |
|
243 | - * |
|
244 | - * @param $pgt_iou the PGT iou |
|
245 | - * |
|
246 | - * @return false|string corresponding PGT, or FALSE on error |
|
247 | - * |
|
248 | - * @public |
|
249 | - */ |
|
250 | - function read($pgt_iou) |
|
240 | + /** |
|
241 | + * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | + * corresponding file. |
|
243 | + * |
|
244 | + * @param $pgt_iou the PGT iou |
|
245 | + * |
|
246 | + * @return false|string corresponding PGT, or FALSE on error |
|
247 | + * |
|
248 | + * @public |
|
249 | + */ |
|
250 | + function read($pgt_iou) |
|
251 | 251 | { |
252 | - phpCAS::traceBegin(); |
|
253 | - $pgt = FALSE; |
|
254 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | - if ( !($f=fopen($fname,"r")) ) { |
|
256 | - phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | - } else { |
|
258 | - if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | - phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | - } |
|
261 | - fclose($f); |
|
262 | - } |
|
252 | + phpCAS::traceBegin(); |
|
253 | + $pgt = FALSE; |
|
254 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | + if ( !($f=fopen($fname,"r")) ) { |
|
256 | + phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | + } else { |
|
258 | + if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | + phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | + } |
|
261 | + fclose($f); |
|
262 | + } |
|
263 | 263 | |
264 | - // delete the PGT file |
|
265 | - @unlink($fname); |
|
264 | + // delete the PGT file |
|
265 | + @unlink($fname); |
|
266 | 266 | |
267 | - phpCAS::traceEnd($pgt); |
|
268 | - return $pgt; |
|
267 | + phpCAS::traceEnd($pgt); |
|
268 | + return $pgt; |
|
269 | 269 | } |
270 | 270 | |
271 | - /** @} */ |
|
271 | + /** @} */ |
|
272 | 272 | |
273 | 273 | } |
274 | 274 |
@@ -56,7 +56,7 @@ |
||
56 | 56 | /** |
57 | 57 | * The constructor of the class, should be called only by inherited classes. |
58 | 58 | * |
59 | - * @param $cas_parent the CASclient instance that creates the current object. |
|
59 | + * @param CASClient $cas_parent the CASclient instance that creates the current object. |
|
60 | 60 | * |
61 | 61 | * @protected |
62 | 62 | */ |
@@ -44,167 +44,167 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorage |
|
49 | - * @{ |
|
50 | - */ |
|
51 | - |
|
52 | - // ######################################################################## |
|
53 | - // CONSTRUCTOR |
|
54 | - // ######################################################################## |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorage |
|
49 | + * @{ |
|
50 | + */ |
|
51 | + |
|
52 | + // ######################################################################## |
|
53 | + // CONSTRUCTOR |
|
54 | + // ######################################################################## |
|
55 | 55 | |
56 | - /** |
|
57 | - * The constructor of the class, should be called only by inherited classes. |
|
58 | - * |
|
59 | - * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | - * |
|
61 | - * @protected |
|
62 | - */ |
|
63 | - function PGTStorage($cas_parent) |
|
56 | + /** |
|
57 | + * The constructor of the class, should be called only by inherited classes. |
|
58 | + * |
|
59 | + * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | + * |
|
61 | + * @protected |
|
62 | + */ |
|
63 | + function PGTStorage($cas_parent) |
|
64 | 64 | { |
65 | - phpCAS::traceBegin(); |
|
66 | - if ( !$cas_parent->isProxy() ) { |
|
67 | - phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | - } |
|
69 | - phpCAS::traceEnd(); |
|
65 | + phpCAS::traceBegin(); |
|
66 | + if ( !$cas_parent->isProxy() ) { |
|
67 | + phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | + } |
|
69 | + phpCAS::traceEnd(); |
|
70 | 70 | } |
71 | 71 | |
72 | - // ######################################################################## |
|
73 | - // DEBUGGING |
|
74 | - // ######################################################################## |
|
72 | + // ######################################################################## |
|
73 | + // DEBUGGING |
|
74 | + // ######################################################################## |
|
75 | 75 | |
76 | - /** |
|
77 | - * This virtual method returns an informational string giving the type of storage |
|
78 | - * used by the object (used for debugging purposes). |
|
79 | - * |
|
80 | - * @public |
|
81 | - */ |
|
82 | - function getStorageType() |
|
76 | + /** |
|
77 | + * This virtual method returns an informational string giving the type of storage |
|
78 | + * used by the object (used for debugging purposes). |
|
79 | + * |
|
80 | + * @public |
|
81 | + */ |
|
82 | + function getStorageType() |
|
83 | 83 | { |
84 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
84 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * This virtual method returns an informational string giving informations on the |
|
89 | - * parameters of the storage.(used for debugging purposes). |
|
90 | - * |
|
91 | - * @public |
|
92 | - */ |
|
93 | - function getStorageInfo() |
|
87 | + /** |
|
88 | + * This virtual method returns an informational string giving informations on the |
|
89 | + * parameters of the storage.(used for debugging purposes). |
|
90 | + * |
|
91 | + * @public |
|
92 | + */ |
|
93 | + function getStorageInfo() |
|
94 | 94 | { |
95 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
95 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
96 | 96 | } |
97 | 97 | |
98 | - // ######################################################################## |
|
99 | - // ERROR HANDLING |
|
100 | - // ######################################################################## |
|
98 | + // ######################################################################## |
|
99 | + // ERROR HANDLING |
|
100 | + // ######################################################################## |
|
101 | 101 | |
102 | - /** |
|
103 | - * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | - * read by PGTStorage::getErrorMessage(). |
|
105 | - * |
|
106 | - * @hideinitializer |
|
107 | - * @private |
|
108 | - * @deprecated not used. |
|
109 | - */ |
|
110 | - var $_error_message=FALSE; |
|
111 | - |
|
112 | - /** |
|
113 | - * This method sets en error message, which can be read later by |
|
114 | - * PGTStorage::getErrorMessage(). |
|
115 | - * |
|
116 | - * @param $error_message an error message |
|
117 | - * |
|
118 | - * @protected |
|
119 | - * @deprecated not used. |
|
120 | - */ |
|
121 | - function setErrorMessage($error_message) |
|
102 | + /** |
|
103 | + * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | + * read by PGTStorage::getErrorMessage(). |
|
105 | + * |
|
106 | + * @hideinitializer |
|
107 | + * @private |
|
108 | + * @deprecated not used. |
|
109 | + */ |
|
110 | + var $_error_message=FALSE; |
|
111 | + |
|
112 | + /** |
|
113 | + * This method sets en error message, which can be read later by |
|
114 | + * PGTStorage::getErrorMessage(). |
|
115 | + * |
|
116 | + * @param $error_message an error message |
|
117 | + * |
|
118 | + * @protected |
|
119 | + * @deprecated not used. |
|
120 | + */ |
|
121 | + function setErrorMessage($error_message) |
|
122 | 122 | { |
123 | - $this->_error_message = $error_message; |
|
123 | + $this->_error_message = $error_message; |
|
124 | 124 | } |
125 | 125 | |
126 | - /** |
|
127 | - * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | - * |
|
129 | - * @return boolean error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | - * otherwise. |
|
131 | - * |
|
132 | - * @public |
|
133 | - * @deprecated not used. |
|
134 | - */ |
|
135 | - function getErrorMessage() |
|
126 | + /** |
|
127 | + * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | + * |
|
129 | + * @return boolean error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | + * otherwise. |
|
131 | + * |
|
132 | + * @public |
|
133 | + * @deprecated not used. |
|
134 | + */ |
|
135 | + function getErrorMessage() |
|
136 | 136 | { |
137 | - return $this->_error_message; |
|
137 | + return $this->_error_message; |
|
138 | 138 | } |
139 | 139 | |
140 | - // ######################################################################## |
|
141 | - // INITIALIZATION |
|
142 | - // ######################################################################## |
|
143 | - |
|
144 | - /** |
|
145 | - * a boolean telling if the storage has already been initialized. Written by |
|
146 | - * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | - * |
|
148 | - * @hideinitializer |
|
149 | - * @private |
|
150 | - */ |
|
151 | - var $_initialized = FALSE; |
|
152 | - |
|
153 | - /** |
|
154 | - * This method tells if the storage has already been intialized. |
|
155 | - * |
|
156 | - * @return boolean boolean |
|
157 | - * |
|
158 | - * @protected |
|
159 | - */ |
|
160 | - function isInitialized() |
|
140 | + // ######################################################################## |
|
141 | + // INITIALIZATION |
|
142 | + // ######################################################################## |
|
143 | + |
|
144 | + /** |
|
145 | + * a boolean telling if the storage has already been initialized. Written by |
|
146 | + * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | + * |
|
148 | + * @hideinitializer |
|
149 | + * @private |
|
150 | + */ |
|
151 | + var $_initialized = FALSE; |
|
152 | + |
|
153 | + /** |
|
154 | + * This method tells if the storage has already been intialized. |
|
155 | + * |
|
156 | + * @return boolean boolean |
|
157 | + * |
|
158 | + * @protected |
|
159 | + */ |
|
160 | + function isInitialized() |
|
161 | 161 | { |
162 | - return $this->_initialized; |
|
162 | + return $this->_initialized; |
|
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * This virtual method initializes the object. |
|
167 | - * |
|
168 | - * @protected |
|
169 | - */ |
|
170 | - function init() |
|
165 | + /** |
|
166 | + * This virtual method initializes the object. |
|
167 | + * |
|
168 | + * @protected |
|
169 | + */ |
|
170 | + function init() |
|
171 | 171 | { |
172 | - $this->_initialized = TRUE; |
|
172 | + $this->_initialized = TRUE; |
|
173 | 173 | } |
174 | 174 | |
175 | - // ######################################################################## |
|
176 | - // PGT I/O |
|
177 | - // ######################################################################## |
|
178 | - |
|
179 | - /** |
|
180 | - * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | - * @note Should never be called. |
|
182 | - * |
|
183 | - * @param $pgt the PGT |
|
184 | - * @param $pgt_iou the PGT iou |
|
185 | - * |
|
186 | - * @protected |
|
187 | - */ |
|
188 | - function write($pgt,$pgt_iou) |
|
175 | + // ######################################################################## |
|
176 | + // PGT I/O |
|
177 | + // ######################################################################## |
|
178 | + |
|
179 | + /** |
|
180 | + * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | + * @note Should never be called. |
|
182 | + * |
|
183 | + * @param $pgt the PGT |
|
184 | + * @param $pgt_iou the PGT iou |
|
185 | + * |
|
186 | + * @protected |
|
187 | + */ |
|
188 | + function write($pgt,$pgt_iou) |
|
189 | 189 | { |
190 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
190 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | - * the corresponding storage entry. |
|
196 | - * @note Should never be called. |
|
197 | - * |
|
198 | - * @param $pgt_iou the PGT iou |
|
199 | - * |
|
200 | - * @protected |
|
201 | - */ |
|
202 | - function read($pgt_iou) |
|
193 | + /** |
|
194 | + * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | + * the corresponding storage entry. |
|
196 | + * @note Should never be called. |
|
197 | + * |
|
198 | + * @param $pgt_iou the PGT iou |
|
199 | + * |
|
200 | + * @protected |
|
201 | + */ |
|
202 | + function read($pgt_iou) |
|
203 | 203 | { |
204 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
204 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
205 | 205 | } |
206 | 206 | |
207 | - /** @} */ |
|
207 | + /** @} */ |
|
208 | 208 | |
209 | 209 | } |
210 | 210 |
@@ -242,6 +242,9 @@ |
||
242 | 242 | return $hmac; |
243 | 243 | } |
244 | 244 | |
245 | +/** |
|
246 | + * @param string|false $text |
|
247 | + */ |
|
245 | 248 | function _openid_sha1($text) { |
246 | 249 | $hex = sha1($text); |
247 | 250 | $raw = ''; |
@@ -45,175 +45,175 @@ |
||
45 | 45 | |
46 | 46 | class PGTStorageDB extends PGTStorage |
47 | 47 | { |
48 | - /** |
|
49 | - * @addtogroup internalPGTStorageDB |
|
50 | - * @{ |
|
51 | - */ |
|
52 | - |
|
53 | - /** |
|
54 | - * a string representing a PEAR DB URL to connect to the database. Written by |
|
55 | - * PGTStorageDB::PGTStorageDB(), read by getURL(). |
|
56 | - * |
|
57 | - * @hideinitializer |
|
58 | - * @private |
|
59 | - */ |
|
60 | - var $_url=''; |
|
61 | - |
|
62 | - /** |
|
63 | - * This method returns the PEAR DB URL to use to connect to the database. |
|
64 | - * |
|
65 | - * @return string PEAR DB URL |
|
66 | - * |
|
67 | - * @private |
|
68 | - */ |
|
69 | - function getURL() |
|
48 | + /** |
|
49 | + * @addtogroup internalPGTStorageDB |
|
50 | + * @{ |
|
51 | + */ |
|
52 | + |
|
53 | + /** |
|
54 | + * a string representing a PEAR DB URL to connect to the database. Written by |
|
55 | + * PGTStorageDB::PGTStorageDB(), read by getURL(). |
|
56 | + * |
|
57 | + * @hideinitializer |
|
58 | + * @private |
|
59 | + */ |
|
60 | + var $_url=''; |
|
61 | + |
|
62 | + /** |
|
63 | + * This method returns the PEAR DB URL to use to connect to the database. |
|
64 | + * |
|
65 | + * @return string PEAR DB URL |
|
66 | + * |
|
67 | + * @private |
|
68 | + */ |
|
69 | + function getURL() |
|
70 | 70 | { |
71 | - return $this->_url; |
|
71 | + return $this->_url; |
|
72 | 72 | } |
73 | 73 | |
74 | - /** |
|
75 | - * The handle of the connection to the database where PGT's are stored. Written by |
|
76 | - * PGTStorageDB::init(), read by getLink(). |
|
77 | - * |
|
78 | - * @hideinitializer |
|
79 | - * @private |
|
80 | - */ |
|
81 | - var $_link = null; |
|
82 | - |
|
83 | - /** |
|
84 | - * This method returns the handle of the connection to the database where PGT's are |
|
85 | - * stored. |
|
86 | - * |
|
87 | - * @return a handle of connection. |
|
88 | - * |
|
89 | - * @private |
|
90 | - */ |
|
91 | - function getLink() |
|
74 | + /** |
|
75 | + * The handle of the connection to the database where PGT's are stored. Written by |
|
76 | + * PGTStorageDB::init(), read by getLink(). |
|
77 | + * |
|
78 | + * @hideinitializer |
|
79 | + * @private |
|
80 | + */ |
|
81 | + var $_link = null; |
|
82 | + |
|
83 | + /** |
|
84 | + * This method returns the handle of the connection to the database where PGT's are |
|
85 | + * stored. |
|
86 | + * |
|
87 | + * @return a handle of connection. |
|
88 | + * |
|
89 | + * @private |
|
90 | + */ |
|
91 | + function getLink() |
|
92 | 92 | { |
93 | - return $this->_link; |
|
93 | + return $this->_link; |
|
94 | 94 | } |
95 | 95 | |
96 | - /** |
|
97 | - * The name of the table where PGT's are stored. Written by |
|
98 | - * PGTStorageDB::PGTStorageDB(), read by getTable(). |
|
99 | - * |
|
100 | - * @hideinitializer |
|
101 | - * @private |
|
102 | - */ |
|
103 | - var $_table = ''; |
|
104 | - |
|
105 | - /** |
|
106 | - * This method returns the name of the table where PGT's are stored. |
|
107 | - * |
|
108 | - * @return string name of a table. |
|
109 | - * |
|
110 | - * @private |
|
111 | - */ |
|
112 | - function getTable() |
|
96 | + /** |
|
97 | + * The name of the table where PGT's are stored. Written by |
|
98 | + * PGTStorageDB::PGTStorageDB(), read by getTable(). |
|
99 | + * |
|
100 | + * @hideinitializer |
|
101 | + * @private |
|
102 | + */ |
|
103 | + var $_table = ''; |
|
104 | + |
|
105 | + /** |
|
106 | + * This method returns the name of the table where PGT's are stored. |
|
107 | + * |
|
108 | + * @return string name of a table. |
|
109 | + * |
|
110 | + * @private |
|
111 | + */ |
|
112 | + function getTable() |
|
113 | 113 | { |
114 | - return $this->_table; |
|
114 | + return $this->_table; |
|
115 | 115 | } |
116 | 116 | |
117 | - // ######################################################################## |
|
118 | - // DEBUGGING |
|
119 | - // ######################################################################## |
|
117 | + // ######################################################################## |
|
118 | + // DEBUGGING |
|
119 | + // ######################################################################## |
|
120 | 120 | |
121 | - /** |
|
122 | - * This method returns an informational string giving the type of storage |
|
123 | - * used by the object (used for debugging purposes). |
|
124 | - * |
|
125 | - * @return string informational string. |
|
126 | - * @public |
|
127 | - */ |
|
128 | - function getStorageType() |
|
121 | + /** |
|
122 | + * This method returns an informational string giving the type of storage |
|
123 | + * used by the object (used for debugging purposes). |
|
124 | + * |
|
125 | + * @return string informational string. |
|
126 | + * @public |
|
127 | + */ |
|
128 | + function getStorageType() |
|
129 | 129 | { |
130 | - return "database"; |
|
130 | + return "database"; |
|
131 | 131 | } |
132 | 132 | |
133 | - /** |
|
134 | - * This method returns an informational string giving informations on the |
|
135 | - * parameters of the storage.(used for debugging purposes). |
|
136 | - * |
|
137 | - * @public |
|
138 | - */ |
|
139 | - function getStorageInfo() |
|
133 | + /** |
|
134 | + * This method returns an informational string giving informations on the |
|
135 | + * parameters of the storage.(used for debugging purposes). |
|
136 | + * |
|
137 | + * @public |
|
138 | + */ |
|
139 | + function getStorageInfo() |
|
140 | 140 | { |
141 | - return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; |
|
141 | + return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; |
|
142 | 142 | } |
143 | 143 | |
144 | - // ######################################################################## |
|
145 | - // CONSTRUCTOR |
|
146 | - // ######################################################################## |
|
144 | + // ######################################################################## |
|
145 | + // CONSTRUCTOR |
|
146 | + // ######################################################################## |
|
147 | 147 | |
148 | - /** |
|
149 | - * The class constructor, called by CASClient::SetPGTStorageDB(). |
|
150 | - * |
|
151 | - * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
152 | - * @param $user the user to access the data with |
|
153 | - * @param $password the user's password |
|
154 | - * @param $database_type the type of the database hosting the data |
|
155 | - * @param $hostname the server hosting the database |
|
156 | - * @param $port the port the server is listening on |
|
157 | - * @param $database the name of the database |
|
158 | - * @param $table the name of the table storing the data |
|
159 | - * |
|
160 | - * @public |
|
161 | - */ |
|
162 | - function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
148 | + /** |
|
149 | + * The class constructor, called by CASClient::SetPGTStorageDB(). |
|
150 | + * |
|
151 | + * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
152 | + * @param $user the user to access the data with |
|
153 | + * @param $password the user's password |
|
154 | + * @param $database_type the type of the database hosting the data |
|
155 | + * @param $hostname the server hosting the database |
|
156 | + * @param $port the port the server is listening on |
|
157 | + * @param $database the name of the database |
|
158 | + * @param $table the name of the table storing the data |
|
159 | + * |
|
160 | + * @public |
|
161 | + */ |
|
162 | + function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
163 | 163 | { |
164 | - phpCAS::traceBegin(); |
|
164 | + phpCAS::traceBegin(); |
|
165 | 165 | |
166 | - // call the ancestor's constructor |
|
167 | - $this->PGTStorage($cas_parent); |
|
166 | + // call the ancestor's constructor |
|
167 | + $this->PGTStorage($cas_parent); |
|
168 | 168 | |
169 | - if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | - if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | - if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | - if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | - if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
169 | + if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | + if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | + if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | + if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | + if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
174 | 174 | |
175 | - // build and store the PEAR DB URL |
|
176 | - $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
|
175 | + // build and store the PEAR DB URL |
|
176 | + $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
|
177 | 177 | |
178 | - // XXX should use setURL and setTable |
|
179 | - phpCAS::traceEnd(); |
|
178 | + // XXX should use setURL and setTable |
|
179 | + phpCAS::traceEnd(); |
|
180 | 180 | } |
181 | 181 | |
182 | - // ######################################################################## |
|
183 | - // INITIALIZATION |
|
184 | - // ######################################################################## |
|
182 | + // ######################################################################## |
|
183 | + // INITIALIZATION |
|
184 | + // ######################################################################## |
|
185 | 185 | |
186 | - /** |
|
187 | - * This method is used to initialize the storage. Halts on error. |
|
188 | - * |
|
189 | - * @public |
|
190 | - */ |
|
191 | - function init() |
|
186 | + /** |
|
187 | + * This method is used to initialize the storage. Halts on error. |
|
188 | + * |
|
189 | + * @public |
|
190 | + */ |
|
191 | + function init() |
|
192 | 192 | { |
193 | - phpCAS::traceBegin(); |
|
194 | - // if the storage has already been initialized, return immediatly |
|
195 | - if ( $this->isInitialized() ) |
|
196 | - return; |
|
197 | - // call the ancestor's method (mark as initialized) |
|
198 | - parent::init(); |
|
193 | + phpCAS::traceBegin(); |
|
194 | + // if the storage has already been initialized, return immediatly |
|
195 | + if ( $this->isInitialized() ) |
|
196 | + return; |
|
197 | + // call the ancestor's method (mark as initialized) |
|
198 | + parent::init(); |
|
199 | 199 | |
200 | - //include phpDB library (the test was introduced in release 0.4.8 for |
|
201 | - //the integration into Tikiwiki). |
|
202 | - if (!class_exists('DB')) { |
|
203 | - include_once('DB.php'); |
|
204 | - } |
|
205 | - |
|
206 | - // try to connect to the database |
|
207 | - $this->_link = DB::connect($this->getURL()); |
|
208 | - if ( DB::isError($this->_link) ) { |
|
209 | - phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
|
210 | - } |
|
211 | - // Dump into trace |
|
212 | - var_dump($this->_link); |
|
213 | - phpCAS::traceBEnd(); |
|
200 | + //include phpDB library (the test was introduced in release 0.4.8 for |
|
201 | + //the integration into Tikiwiki). |
|
202 | + if (!class_exists('DB')) { |
|
203 | + include_once('DB.php'); |
|
204 | + } |
|
205 | + |
|
206 | + // try to connect to the database |
|
207 | + $this->_link = DB::connect($this->getURL()); |
|
208 | + if ( DB::isError($this->_link) ) { |
|
209 | + phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
|
210 | + } |
|
211 | + // Dump into trace |
|
212 | + var_dump($this->_link); |
|
213 | + phpCAS::traceBEnd(); |
|
214 | 214 | } |
215 | 215 | |
216 | - /** @} */ |
|
216 | + /** @} */ |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | ?> |
220 | 220 | \ No newline at end of file |
@@ -33,99 +33,99 @@ discard block |
||
33 | 33 | class SignedRequest |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $rawSignedRequest; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $payload; |
|
45 | - |
|
46 | - /** |
|
47 | - * Instantiate a new SignedRequest entity. |
|
48 | - * |
|
49 | - * @param string|null $rawSignedRequest The raw signed request. |
|
50 | - * @param string|null $state random string to prevent CSRF. |
|
51 | - * @param string|null $appSecret |
|
52 | - */ |
|
53 | - public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | - { |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $rawSignedRequest; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $payload; |
|
45 | + |
|
46 | + /** |
|
47 | + * Instantiate a new SignedRequest entity. |
|
48 | + * |
|
49 | + * @param string|null $rawSignedRequest The raw signed request. |
|
50 | + * @param string|null $state random string to prevent CSRF. |
|
51 | + * @param string|null $appSecret |
|
52 | + */ |
|
53 | + public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | + { |
|
55 | 55 | if (!$rawSignedRequest) { |
56 | - return; |
|
56 | + return; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->rawSignedRequest = $rawSignedRequest; |
60 | 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns the raw signed request data. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getRawSignedRequest() |
|
69 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns the raw signed request data. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getRawSignedRequest() |
|
69 | + { |
|
70 | 70 | return $this->rawSignedRequest; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the parsed signed request data. |
|
75 | - * |
|
76 | - * @return array|null |
|
77 | - */ |
|
78 | - public function getPayload() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the parsed signed request data. |
|
75 | + * |
|
76 | + * @return array|null |
|
77 | + */ |
|
78 | + public function getPayload() |
|
79 | + { |
|
80 | 80 | return $this->payload; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns a property from the signed request data if available. |
|
85 | - * |
|
86 | - * @param string $key |
|
87 | - * @param integer $default |
|
88 | - * |
|
89 | - * @return mixed|null |
|
90 | - */ |
|
91 | - public function get($key, $default = null) |
|
92 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns a property from the signed request data if available. |
|
85 | + * |
|
86 | + * @param string $key |
|
87 | + * @param integer $default |
|
88 | + * |
|
89 | + * @return mixed|null |
|
90 | + */ |
|
91 | + public function get($key, $default = null) |
|
92 | + { |
|
93 | 93 | if (isset($this->payload[$key])) { |
94 | - return $this->payload[$key]; |
|
94 | + return $this->payload[$key]; |
|
95 | 95 | } |
96 | 96 | return $default; |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns user_id from signed request data if available. |
|
101 | - * |
|
102 | - * @return string|null |
|
103 | - */ |
|
104 | - public function getUserId() |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns user_id from signed request data if available. |
|
101 | + * |
|
102 | + * @return string|null |
|
103 | + */ |
|
104 | + public function getUserId() |
|
105 | + { |
|
106 | 106 | return $this->get('user_id'); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Checks for OAuth data in the payload. |
|
111 | - * |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function hasOAuthData() |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Checks for OAuth data in the payload. |
|
111 | + * |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function hasOAuthData() |
|
115 | + { |
|
116 | 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Creates a signed request from an array of data. |
|
121 | - * |
|
122 | - * @param array $payload |
|
123 | - * @param string|null $appSecret |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function make(array $payload, $appSecret = null) |
|
128 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Creates a signed request from an array of data. |
|
121 | + * |
|
122 | + * @param array $payload |
|
123 | + * @param string|null $appSecret |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function make(array $payload, $appSecret = null) |
|
128 | + { |
|
129 | 129 | $payload['algorithm'] = 'HMAC-SHA256'; |
130 | 130 | $payload['issued_at'] = time(); |
131 | 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | $encodedSig = static::base64UrlEncode($hashedSig); |
135 | 135 | |
136 | 136 | return $encodedSig.'.'.$encodedPayload; |
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Validates and decodes a signed request and returns |
|
141 | - * the payload as an array. |
|
142 | - * |
|
143 | - * @param string $signedRequest |
|
144 | - * @param string|null $state |
|
145 | - * @param string|null $appSecret |
|
146 | - * |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | - { |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Validates and decodes a signed request and returns |
|
141 | + * the payload as an array. |
|
142 | + * |
|
143 | + * @param string $signedRequest |
|
144 | + * @param string|null $state |
|
145 | + * @param string|null $appSecret |
|
146 | + * |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | + { |
|
151 | 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); |
152 | 152 | |
153 | 153 | // Signature validation |
@@ -159,228 +159,228 @@ discard block |
||
159 | 159 | $data = static::decodePayload($encodedPayload); |
160 | 160 | static::validateAlgorithm($data); |
161 | 161 | if ($state) { |
162 | - static::validateCsrf($data, $state); |
|
162 | + static::validateCsrf($data, $state); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $data; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Validates the format of a signed request. |
|
170 | - * |
|
171 | - * @param string $signedRequest |
|
172 | - * |
|
173 | - * @throws FacebookSDKException |
|
174 | - */ |
|
175 | - public static function validateFormat($signedRequest) |
|
176 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Validates the format of a signed request. |
|
170 | + * |
|
171 | + * @param string $signedRequest |
|
172 | + * |
|
173 | + * @throws FacebookSDKException |
|
174 | + */ |
|
175 | + public static function validateFormat($signedRequest) |
|
176 | + { |
|
177 | 177 | if (strpos($signedRequest, '.') !== false) { |
178 | - return; |
|
178 | + return; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | throw new FacebookSDKException( |
182 | - 'Malformed signed request.', 606 |
|
182 | + 'Malformed signed request.', 606 |
|
183 | 183 | ); |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Decodes a raw valid signed request. |
|
188 | - * |
|
189 | - * @param string $signedRequest |
|
190 | - * |
|
191 | - * @returns array |
|
192 | - */ |
|
193 | - public static function split($signedRequest) |
|
194 | - { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Decodes a raw valid signed request. |
|
188 | + * |
|
189 | + * @param string $signedRequest |
|
190 | + * |
|
191 | + * @returns array |
|
192 | + */ |
|
193 | + public static function split($signedRequest) |
|
194 | + { |
|
195 | 195 | static::validateFormat($signedRequest); |
196 | 196 | |
197 | 197 | return explode('.', $signedRequest, 2); |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Decodes the raw signature from a signed request. |
|
202 | - * |
|
203 | - * @param string $encodedSig |
|
204 | - * |
|
205 | - * @returns string |
|
206 | - * |
|
207 | - * @throws FacebookSDKException |
|
208 | - */ |
|
209 | - public static function decodeSignature($encodedSig) |
|
210 | - { |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Decodes the raw signature from a signed request. |
|
202 | + * |
|
203 | + * @param string $encodedSig |
|
204 | + * |
|
205 | + * @returns string |
|
206 | + * |
|
207 | + * @throws FacebookSDKException |
|
208 | + */ |
|
209 | + public static function decodeSignature($encodedSig) |
|
210 | + { |
|
211 | 211 | $sig = static::base64UrlDecode($encodedSig); |
212 | 212 | |
213 | 213 | if ($sig) { |
214 | - return $sig; |
|
214 | + return $sig; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | throw new FacebookSDKException( |
218 | - 'Signed request has malformed encoded signature data.', 607 |
|
218 | + 'Signed request has malformed encoded signature data.', 607 |
|
219 | 219 | ); |
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Decodes the raw payload from a signed request. |
|
224 | - * |
|
225 | - * @param string $encodedPayload |
|
226 | - * |
|
227 | - * @returns array |
|
228 | - * |
|
229 | - * @throws FacebookSDKException |
|
230 | - */ |
|
231 | - public static function decodePayload($encodedPayload) |
|
232 | - { |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Decodes the raw payload from a signed request. |
|
224 | + * |
|
225 | + * @param string $encodedPayload |
|
226 | + * |
|
227 | + * @returns array |
|
228 | + * |
|
229 | + * @throws FacebookSDKException |
|
230 | + */ |
|
231 | + public static function decodePayload($encodedPayload) |
|
232 | + { |
|
233 | 233 | $payload = static::base64UrlDecode($encodedPayload); |
234 | 234 | |
235 | 235 | if ($payload) { |
236 | - $payload = json_decode($payload, true); |
|
236 | + $payload = json_decode($payload, true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | if (is_array($payload)) { |
240 | - return $payload; |
|
240 | + return $payload; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | throw new FacebookSDKException( |
244 | - 'Signed request has malformed encoded payload data.', 607 |
|
244 | + 'Signed request has malformed encoded payload data.', 607 |
|
245 | 245 | ); |
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Validates the algorithm used in a signed request. |
|
250 | - * |
|
251 | - * @param array $data |
|
252 | - * |
|
253 | - * @throws FacebookSDKException |
|
254 | - */ |
|
255 | - public static function validateAlgorithm(array $data) |
|
256 | - { |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Validates the algorithm used in a signed request. |
|
250 | + * |
|
251 | + * @param array $data |
|
252 | + * |
|
253 | + * @throws FacebookSDKException |
|
254 | + */ |
|
255 | + public static function validateAlgorithm(array $data) |
|
256 | + { |
|
257 | 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { |
258 | - return; |
|
258 | + return; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | throw new FacebookSDKException( |
262 | - 'Signed request is using the wrong algorithm.', 605 |
|
262 | + 'Signed request is using the wrong algorithm.', 605 |
|
263 | 263 | ); |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Hashes the signature used in a signed request. |
|
268 | - * |
|
269 | - * @param string $encodedData |
|
270 | - * @param string|null $appSecret |
|
271 | - * |
|
272 | - * @return string |
|
273 | - * |
|
274 | - * @throws FacebookSDKException |
|
275 | - */ |
|
276 | - public static function hashSignature($encodedData, $appSecret = null) |
|
277 | - { |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Hashes the signature used in a signed request. |
|
268 | + * |
|
269 | + * @param string $encodedData |
|
270 | + * @param string|null $appSecret |
|
271 | + * |
|
272 | + * @return string |
|
273 | + * |
|
274 | + * @throws FacebookSDKException |
|
275 | + */ |
|
276 | + public static function hashSignature($encodedData, $appSecret = null) |
|
277 | + { |
|
278 | 278 | $hashedSig = hash_hmac( |
279 | - 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
279 | + 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | if ($hashedSig) { |
283 | - return $hashedSig; |
|
283 | + return $hashedSig; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | throw new FacebookSDKException( |
287 | - 'Unable to hash signature from encoded payload data.', 602 |
|
287 | + 'Unable to hash signature from encoded payload data.', 602 |
|
288 | 288 | ); |
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Validates the signature used in a signed request. |
|
293 | - * |
|
294 | - * @param string $hashedSig |
|
295 | - * @param string $sig |
|
296 | - * |
|
297 | - * @throws FacebookSDKException |
|
298 | - */ |
|
299 | - public static function validateSignature($hashedSig, $sig) |
|
300 | - { |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Validates the signature used in a signed request. |
|
293 | + * |
|
294 | + * @param string $hashedSig |
|
295 | + * @param string $sig |
|
296 | + * |
|
297 | + * @throws FacebookSDKException |
|
298 | + */ |
|
299 | + public static function validateSignature($hashedSig, $sig) |
|
300 | + { |
|
301 | 301 | if (mb_strlen($hashedSig) === mb_strlen($sig)) { |
302 | - $validate = 0; |
|
303 | - for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
302 | + $validate = 0; |
|
303 | + for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
304 | 304 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); |
305 | - } |
|
306 | - if ($validate === 0) { |
|
305 | + } |
|
306 | + if ($validate === 0) { |
|
307 | 307 | return; |
308 | - } |
|
308 | + } |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | throw new FacebookSDKException( |
312 | - 'Signed request has an invalid signature.', 602 |
|
312 | + 'Signed request has an invalid signature.', 602 |
|
313 | 313 | ); |
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Validates a signed request against CSRF. |
|
318 | - * |
|
319 | - * @param array $data |
|
320 | - * @param string $state |
|
321 | - * |
|
322 | - * @throws FacebookSDKException |
|
323 | - */ |
|
324 | - public static function validateCsrf(array $data, $state) |
|
325 | - { |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Validates a signed request against CSRF. |
|
318 | + * |
|
319 | + * @param array $data |
|
320 | + * @param string $state |
|
321 | + * |
|
322 | + * @throws FacebookSDKException |
|
323 | + */ |
|
324 | + public static function validateCsrf(array $data, $state) |
|
325 | + { |
|
326 | 326 | if (isset($data['state']) && $data['state'] === $state) { |
327 | - return; |
|
327 | + return; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | throw new FacebookSDKException( |
331 | - 'Signed request did not pass CSRF validation.', 604 |
|
331 | + 'Signed request did not pass CSRF validation.', 604 |
|
332 | 332 | ); |
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Base64 decoding which replaces characters: |
|
337 | - * + instead of - |
|
338 | - * / instead of _ |
|
339 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | - * |
|
341 | - * @param string $input base64 url encoded input |
|
342 | - * |
|
343 | - * @return string decoded string |
|
344 | - */ |
|
345 | - public static function base64UrlDecode($input) |
|
346 | - { |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Base64 decoding which replaces characters: |
|
337 | + * + instead of - |
|
338 | + * / instead of _ |
|
339 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | + * |
|
341 | + * @param string $input base64 url encoded input |
|
342 | + * |
|
343 | + * @return string decoded string |
|
344 | + */ |
|
345 | + public static function base64UrlDecode($input) |
|
346 | + { |
|
347 | 347 | $urlDecodedBase64 = strtr($input, '-_', '+/'); |
348 | 348 | static::validateBase64($urlDecodedBase64); |
349 | 349 | return base64_decode($urlDecodedBase64); |
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Base64 encoding which replaces characters: |
|
354 | - * + instead of - |
|
355 | - * / instead of _ |
|
356 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | - * |
|
358 | - * @param string $input string to encode |
|
359 | - * |
|
360 | - * @return string base64 url encoded input |
|
361 | - */ |
|
362 | - public static function base64UrlEncode($input) |
|
363 | - { |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Base64 encoding which replaces characters: |
|
354 | + * + instead of - |
|
355 | + * / instead of _ |
|
356 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | + * |
|
358 | + * @param string $input string to encode |
|
359 | + * |
|
360 | + * @return string base64 url encoded input |
|
361 | + */ |
|
362 | + public static function base64UrlEncode($input) |
|
363 | + { |
|
364 | 364 | return strtr(base64_encode($input), '+/', '-_'); |
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Validates a base64 string. |
|
369 | - * |
|
370 | - * @param string $input base64 value to validate |
|
371 | - * |
|
372 | - * @throws FacebookSDKException |
|
373 | - */ |
|
374 | - public static function validateBase64($input) |
|
375 | - { |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Validates a base64 string. |
|
369 | + * |
|
370 | + * @param string $input base64 value to validate |
|
371 | + * |
|
372 | + * @throws FacebookSDKException |
|
373 | + */ |
|
374 | + public static function validateBase64($input) |
|
375 | + { |
|
376 | 376 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; |
377 | 377 | if (preg_match($pattern, $input)) { |
378 | - return; |
|
378 | + return; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | throw new FacebookSDKException( |
382 | - 'Signed request contains malformed base64 encoding.', 608 |
|
382 | + 'Signed request contains malformed base64 encoding.', 608 |
|
383 | 383 | ); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |
@@ -35,120 +35,120 @@ discard block |
||
35 | 35 | class AccessToken |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * The access token. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $accessToken; |
|
44 | - |
|
45 | - /** |
|
46 | - * A unique ID to identify a client. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $machineId; |
|
51 | - |
|
52 | - /** |
|
53 | - * Date when token expires. |
|
54 | - * |
|
55 | - * @var \DateTime|null |
|
56 | - */ |
|
57 | - protected $expiresAt; |
|
58 | - |
|
59 | - /** |
|
60 | - * Create a new access token entity. |
|
61 | - * |
|
62 | - * @param string $accessToken |
|
63 | - * @param int $expiresAt |
|
64 | - * @param string|null machineId |
|
65 | - * @param string $machineId |
|
66 | - */ |
|
67 | - public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
68 | - { |
|
38 | + /** |
|
39 | + * The access token. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $accessToken; |
|
44 | + |
|
45 | + /** |
|
46 | + * A unique ID to identify a client. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $machineId; |
|
51 | + |
|
52 | + /** |
|
53 | + * Date when token expires. |
|
54 | + * |
|
55 | + * @var \DateTime|null |
|
56 | + */ |
|
57 | + protected $expiresAt; |
|
58 | + |
|
59 | + /** |
|
60 | + * Create a new access token entity. |
|
61 | + * |
|
62 | + * @param string $accessToken |
|
63 | + * @param int $expiresAt |
|
64 | + * @param string|null machineId |
|
65 | + * @param string $machineId |
|
66 | + */ |
|
67 | + public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
68 | + { |
|
69 | 69 | $this->accessToken = $accessToken; |
70 | 70 | if ($expiresAt) { |
71 | - $this->setExpiresAtFromTimeStamp($expiresAt); |
|
71 | + $this->setExpiresAtFromTimeStamp($expiresAt); |
|
72 | 72 | } |
73 | 73 | $this->machineId = $machineId; |
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Setter for expires_at. |
|
78 | - * |
|
79 | - * @param int $timeStamp |
|
80 | - */ |
|
81 | - protected function setExpiresAtFromTimeStamp($timeStamp) |
|
82 | - { |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Setter for expires_at. |
|
78 | + * |
|
79 | + * @param int $timeStamp |
|
80 | + */ |
|
81 | + protected function setExpiresAtFromTimeStamp($timeStamp) |
|
82 | + { |
|
83 | 83 | $dt = new \DateTime(); |
84 | 84 | $dt->setTimestamp($timeStamp); |
85 | 85 | $this->expiresAt = $dt; |
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Getter for expiresAt. |
|
90 | - * |
|
91 | - * @return \DateTime|null |
|
92 | - */ |
|
93 | - public function getExpiresAt() |
|
94 | - { |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Getter for expiresAt. |
|
90 | + * |
|
91 | + * @return \DateTime|null |
|
92 | + */ |
|
93 | + public function getExpiresAt() |
|
94 | + { |
|
95 | 95 | return $this->expiresAt; |
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Getter for machineId. |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getMachineId() |
|
104 | - { |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Getter for machineId. |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getMachineId() |
|
104 | + { |
|
105 | 105 | return $this->machineId; |
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Determines whether or not this is a long-lived token. |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isLongLived() |
|
114 | - { |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Determines whether or not this is a long-lived token. |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isLongLived() |
|
114 | + { |
|
115 | 115 | if ($this->expiresAt) { |
116 | - return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
116 | + return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
117 | 117 | } |
118 | 118 | return false; |
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Checks the validity of the access token. |
|
123 | - * |
|
124 | - * @param string|null $appId Application ID to use |
|
125 | - * @param string|null $appSecret App secret value to use |
|
126 | - * @param string|null $machineId |
|
127 | - * |
|
128 | - * @return boolean |
|
129 | - */ |
|
130 | - public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
131 | - { |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Checks the validity of the access token. |
|
123 | + * |
|
124 | + * @param string|null $appId Application ID to use |
|
125 | + * @param string|null $appSecret App secret value to use |
|
126 | + * @param string|null $machineId |
|
127 | + * |
|
128 | + * @return boolean |
|
129 | + */ |
|
130 | + public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
131 | + { |
|
132 | 132 | $accessTokenInfo = $this->getInfo($appId, $appSecret); |
133 | 133 | $machineId = $machineId ?: $this->machineId; |
134 | 134 | return static::validateAccessToken($accessTokenInfo, $appId, $machineId); |
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Ensures the provided GraphSessionInfo object is valid, |
|
139 | - * throwing an exception if not. Ensures the appId matches, |
|
140 | - * that the machineId matches if it's being used, |
|
141 | - * that the token is valid and has not expired. |
|
142 | - * |
|
143 | - * @param GraphSessionInfo $tokenInfo |
|
144 | - * @param string|null $appId Application ID to use |
|
145 | - * @param string|null $machineId |
|
146 | - * |
|
147 | - * @return boolean |
|
148 | - */ |
|
149 | - public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
150 | - $appId = null, $machineId = null) |
|
151 | - { |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Ensures the provided GraphSessionInfo object is valid, |
|
139 | + * throwing an exception if not. Ensures the appId matches, |
|
140 | + * that the machineId matches if it's being used, |
|
141 | + * that the token is valid and has not expired. |
|
142 | + * |
|
143 | + * @param GraphSessionInfo $tokenInfo |
|
144 | + * @param string|null $appId Application ID to use |
|
145 | + * @param string|null $machineId |
|
146 | + * |
|
147 | + * @return boolean |
|
148 | + */ |
|
149 | + public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
150 | + $appId = null, $machineId = null) |
|
151 | + { |
|
152 | 152 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
153 | 153 | |
154 | 154 | $appIdIsValid = $tokenInfo->getAppId() == $targetAppId; |
@@ -157,90 +157,90 @@ discard block |
||
157 | 157 | |
158 | 158 | // Not all access tokens return an expiration. E.g. an app access token. |
159 | 159 | if ($tokenInfo->getExpiresAt() instanceof \DateTime) { |
160 | - $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
160 | + $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
161 | 161 | } else { |
162 | - $accessTokenIsStillAlive = true; |
|
162 | + $accessTokenIsStillAlive = true; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get a valid access token from a code. |
|
170 | - * |
|
171 | - * @param string $code |
|
172 | - * @param string|null $appId |
|
173 | - * @param string|null $appSecret |
|
174 | - * @param string|null $machineId |
|
175 | - * |
|
176 | - * @return AccessToken |
|
177 | - */ |
|
178 | - public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
179 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get a valid access token from a code. |
|
170 | + * |
|
171 | + * @param string $code |
|
172 | + * @param string|null $appId |
|
173 | + * @param string|null $appSecret |
|
174 | + * @param string|null $machineId |
|
175 | + * |
|
176 | + * @return AccessToken |
|
177 | + */ |
|
178 | + public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
179 | + { |
|
180 | 180 | $params = array( |
181 | - 'code' => $code, |
|
182 | - 'redirect_uri' => '', |
|
181 | + 'code' => $code, |
|
182 | + 'redirect_uri' => '', |
|
183 | 183 | ); |
184 | 184 | |
185 | 185 | if ($machineId) { |
186 | - $params['machine_id'] = $machineId; |
|
186 | + $params['machine_id'] = $machineId; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | return static::requestAccessToken($params, $appId, $appSecret); |
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Get a valid code from an access token. |
|
194 | - * |
|
195 | - * @param AccessToken $accessToken |
|
196 | - * @param string|null $appId |
|
197 | - * @param string|null $appSecret |
|
198 | - * |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
202 | - { |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Get a valid code from an access token. |
|
194 | + * |
|
195 | + * @param AccessToken $accessToken |
|
196 | + * @param string|null $appId |
|
197 | + * @param string|null $appSecret |
|
198 | + * |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
202 | + { |
|
203 | 203 | $accessToken = (string) $accessToken; |
204 | 204 | |
205 | 205 | $params = array( |
206 | - 'access_token' => $accessToken, |
|
207 | - 'redirect_uri' => '', |
|
206 | + 'access_token' => $accessToken, |
|
207 | + 'redirect_uri' => '', |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | return static::requestCode($params, $appId, $appSecret); |
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Exchanges a short lived access token with a long lived access token. |
|
215 | - * |
|
216 | - * @param string|null $appId |
|
217 | - * @param string|null $appSecret |
|
218 | - * |
|
219 | - * @return AccessToken |
|
220 | - */ |
|
221 | - public function extend($appId = null, $appSecret = null) |
|
222 | - { |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Exchanges a short lived access token with a long lived access token. |
|
215 | + * |
|
216 | + * @param string|null $appId |
|
217 | + * @param string|null $appSecret |
|
218 | + * |
|
219 | + * @return AccessToken |
|
220 | + */ |
|
221 | + public function extend($appId = null, $appSecret = null) |
|
222 | + { |
|
223 | 223 | $params = array( |
224 | - 'grant_type' => 'fb_exchange_token', |
|
225 | - 'fb_exchange_token' => $this->accessToken, |
|
224 | + 'grant_type' => 'fb_exchange_token', |
|
225 | + 'fb_exchange_token' => $this->accessToken, |
|
226 | 226 | ); |
227 | 227 | |
228 | 228 | return static::requestAccessToken($params, $appId, $appSecret); |
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Request an access token based on a set of params. |
|
233 | - * |
|
234 | - * @param array $params |
|
235 | - * @param string|null $appId |
|
236 | - * @param string|null $appSecret |
|
237 | - * |
|
238 | - * @return AccessToken |
|
239 | - * |
|
240 | - * @throws FacebookRequestException |
|
241 | - */ |
|
242 | - public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
243 | - { |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Request an access token based on a set of params. |
|
233 | + * |
|
234 | + * @param array $params |
|
235 | + * @param string|null $appId |
|
236 | + * @param string|null $appSecret |
|
237 | + * |
|
238 | + * @return AccessToken |
|
239 | + * |
|
240 | + * @throws FacebookRequestException |
|
241 | + */ |
|
242 | + public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
243 | + { |
|
244 | 244 | $response = static::request('/oauth/access_token', $params, $appId, $appSecret); |
245 | 245 | $data = $response->getResponse(); |
246 | 246 | |
@@ -249,133 +249,133 @@ discard block |
||
249 | 249 | * @see https://github.com/facebook/facebook-php-sdk-v4/issues/36 |
250 | 250 | */ |
251 | 251 | if (is_array($data)) { |
252 | - if (isset($data['access_token'])) { |
|
252 | + if (isset($data['access_token'])) { |
|
253 | 253 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; |
254 | 254 | return new static($data['access_token'], $expiresAt); |
255 | - } |
|
255 | + } |
|
256 | 256 | } elseif($data instanceof \stdClass) { |
257 | - if (isset($data->access_token)) { |
|
257 | + if (isset($data->access_token)) { |
|
258 | 258 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; |
259 | 259 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; |
260 | 260 | return new static((string) $data->access_token, $expiresAt, $machineId); |
261 | - } |
|
261 | + } |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | throw FacebookRequestException::create( |
265 | - $response->getRawResponse(), |
|
266 | - $data, |
|
267 | - 401 |
|
265 | + $response->getRawResponse(), |
|
266 | + $data, |
|
267 | + 401 |
|
268 | 268 | ); |
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Request a code from a long lived access token. |
|
273 | - * |
|
274 | - * @param array $params |
|
275 | - * @param string|null $appId |
|
276 | - * @param string|null $appSecret |
|
277 | - * |
|
278 | - * @return string |
|
279 | - * |
|
280 | - * @throws FacebookRequestException |
|
281 | - */ |
|
282 | - public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
283 | - { |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Request a code from a long lived access token. |
|
273 | + * |
|
274 | + * @param array $params |
|
275 | + * @param string|null $appId |
|
276 | + * @param string|null $appSecret |
|
277 | + * |
|
278 | + * @return string |
|
279 | + * |
|
280 | + * @throws FacebookRequestException |
|
281 | + */ |
|
282 | + public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
283 | + { |
|
284 | 284 | $response = static::request('/oauth/client_code', $params, $appId, $appSecret); |
285 | 285 | $data = $response->getResponse(); |
286 | 286 | |
287 | 287 | if (isset($data->code)) { |
288 | - return (string) $data->code; |
|
288 | + return (string) $data->code; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | throw FacebookRequestException::create( |
292 | - $response->getRawResponse(), |
|
293 | - $data, |
|
294 | - 401 |
|
292 | + $response->getRawResponse(), |
|
293 | + $data, |
|
294 | + 401 |
|
295 | 295 | ); |
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Send a request to Graph with an app access token. |
|
300 | - * |
|
301 | - * @param string $endpoint |
|
302 | - * @param array $params |
|
303 | - * @param string|null $appId |
|
304 | - * @param string|null $appSecret |
|
305 | - * |
|
306 | - * @return \Facebook\FacebookResponse |
|
307 | - * |
|
308 | - * @throws FacebookRequestException |
|
309 | - */ |
|
310 | - protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
311 | - { |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Send a request to Graph with an app access token. |
|
300 | + * |
|
301 | + * @param string $endpoint |
|
302 | + * @param array $params |
|
303 | + * @param string|null $appId |
|
304 | + * @param string|null $appSecret |
|
305 | + * |
|
306 | + * @return \Facebook\FacebookResponse |
|
307 | + * |
|
308 | + * @throws FacebookRequestException |
|
309 | + */ |
|
310 | + protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
311 | + { |
|
312 | 312 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
313 | 313 | $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret); |
314 | 314 | |
315 | 315 | if (!isset($params['client_id'])) { |
316 | - $params['client_id'] = $targetAppId; |
|
316 | + $params['client_id'] = $targetAppId; |
|
317 | 317 | } |
318 | 318 | if (!isset($params['client_secret'])) { |
319 | - $params['client_secret'] = $targetAppSecret; |
|
319 | + $params['client_secret'] = $targetAppSecret; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // The response for this endpoint is not JSON, so it must be handled |
323 | 323 | // differently, not as a GraphObject. |
324 | 324 | $request = new FacebookRequest( |
325 | - FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
326 | - 'GET', |
|
327 | - $endpoint, |
|
328 | - $params |
|
325 | + FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
326 | + 'GET', |
|
327 | + $endpoint, |
|
328 | + $params |
|
329 | 329 | ); |
330 | 330 | return $request->execute(); |
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Get more info about an access token. |
|
335 | - * |
|
336 | - * @param string|null $appId |
|
337 | - * @param string|null $appSecret |
|
338 | - * |
|
339 | - * @return GraphSessionInfo |
|
340 | - */ |
|
341 | - public function getInfo($appId = null, $appSecret = null) |
|
342 | - { |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Get more info about an access token. |
|
335 | + * |
|
336 | + * @param string|null $appId |
|
337 | + * @param string|null $appSecret |
|
338 | + * |
|
339 | + * @return GraphSessionInfo |
|
340 | + */ |
|
341 | + public function getInfo($appId = null, $appSecret = null) |
|
342 | + { |
|
343 | 343 | $params = array('input_token' => $this->accessToken); |
344 | 344 | |
345 | 345 | $request = new FacebookRequest( |
346 | - FacebookSession::newAppSession($appId, $appSecret), |
|
347 | - 'GET', |
|
348 | - '/debug_token', |
|
349 | - $params |
|
346 | + FacebookSession::newAppSession($appId, $appSecret), |
|
347 | + 'GET', |
|
348 | + '/debug_token', |
|
349 | + $params |
|
350 | 350 | ); |
351 | 351 | $response = $request->execute()->getGraphObject(GraphSessionInfo::className()); |
352 | 352 | |
353 | 353 | // Update the data on this token |
354 | 354 | if ($response->getExpiresAt()) { |
355 | - $this->expiresAt = $response->getExpiresAt(); |
|
355 | + $this->expiresAt = $response->getExpiresAt(); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | return $response; |
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Returns the access token as a string. |
|
363 | - * |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function __toString() |
|
367 | - { |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Returns the access token as a string. |
|
363 | + * |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function __toString() |
|
367 | + { |
|
368 | 368 | return $this->accessToken; |
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Returns true if the access token is an app session token. |
|
373 | - * |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function isAppSession() |
|
377 | - { |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Returns true if the access token is an app session token. |
|
373 | + * |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function isAppSession() |
|
377 | + { |
|
378 | 378 | return strpos($this->accessToken, "|") !== false; |
379 | - } |
|
379 | + } |
|
380 | 380 | |
381 | 381 | } |