forked from MightyGuild/eventbrite-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authenticate.php
36 lines (27 loc) · 1.03 KB
/
Authenticate.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
<?php
define("EVENTBRITE_OAUTH_BASE", "https://www.eventbrite.com/oauth/");
function createAuthorizeUrl($client_key)
{
return EVENTBRITE_OAUTH_BASE . 'authorize?response_type=code&client_id=' . $client_key;
}
function handshake($code, $client_secret, $app_key)
{
$post_args = array('code'=>$code,
'client_secret'=>$client_secret,
'client_id'=>$app_key,
'grant_type'=>'authorization_code');
$data = http_build_query($post_args);
$options = array(
'http'=>array(
'method'=>'POST',
'header'=>"Content-type: application/x-www-form-urlencoded",
'content'=>$data,
'ignore_errors'=>true
)
);
$url = EVENTBRITE_OAUTH_BASE . 'token';
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
/* this is where we will handle errors. Eventbrite errors are a part of the response payload and are returned as an associative array. */
return json_decode($result, true);
}