-
Notifications
You must be signed in to change notification settings - Fork 17
/
RegistrationParser.php
79 lines (73 loc) · 1.85 KB
/
RegistrationParser.php
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
<?php
/**
* Wrappers for facebook plugins.
* @copyright © Digitick <www.digitick.net> 2011
* @license GNU Lesser General Public License v3.0
* @author Ianaré Sévi
*/
/**
* The registration parser is used to convert the JSON response from Facebook
* into a format easily inserted into Yii applications.
*
* THIS IS UNFINISHED, UNTESTED CODE !!
*
* Contributions welcome :-)
*/
class RegistrationParser extends CComponent
{
public $data;
public $app_id;
public $app_secret;
public $mapper;
protected $testData = '{
"oauth_token": "...big long string...",
"algorithm": "HMAC-SHA256",
"expires": 1291840400,
"issued_at": 1291836800,
"registration": {
"name": "Paul Tarjan",
"email": "[email protected]",
"location": {
"name": "San Francisco, California",
"id": 114952118516947
},
"gender": "male",
"birthday": "12/16/1985",
"like": true,
"phone": "555-123-4567",
"anniversary": "2/14/1998",
"captain": "K",
"force": "jedi",
"live": {
"name": "Denver, Colorado",
"id": 115590505119035
}
},
"user_id": "218471"
}';
/**
* change the facebook response to an objet
* @return Object $response
*/
public function parse_signed_request($data = null)
{
if (!$data)
$data = $this->testData;
$data = json_decode($this->testData);
if (strtoupper($data->algorithm) !== 'HMAC-SHA256') {
if (YII_DEBUG)
throw new CException('Unknown algorithm : "' . $data->algorithm . '" . Expected HMAC-SHA256');
return null;
}
return $data->registration;
}
/**
*
* @param $input
* @return string
*/
protected function base64UrlDecode($input)
{
return base64_decode(strtr($input, '-_', '+/'));
}
}