-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.php
34 lines (30 loc) · 883 Bytes
/
token.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
<?php
require("lib/init.php");
$code = getRequiredPost("code");
$me = getRequiredPost("me");
$redirect_uri = getRequiredPost("redirect_uri");
$client_id = getRequiredPost("client_id");
$state = getRequiredPost("state");
$params = array(
"code" => $code,
"me" => $me,
"redirect_uri" => $redirect_uri,
"client_id" => $client_id,
"state" => $state
);
try {
$auth = $site->Auth();
$result = $auth->indieAuthenticate($params);
if (empty($result["me"]) ||
$result["me"] !== $site->url)
do400("Authentication failed for $me");
$token = $auth->generateToken($client_id, $result["scope"]);
header("Content-Type: application/x-www-form-urlencoded");
echo formUrlencode(array(
"access_token" => $token,
"me" => $me,
"scope" => $result["scope"]));
} catch (Exception $e) {
do500($e->getMessage());
}
?>