forked from Tevemadar/LocaliZoomCollab
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcallback.php
67 lines (65 loc) · 2.38 KB
/
callback.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
<?php
ob_start();
$json = json_decode(urldecode(filter_input(INPUT_GET, "state")), true);
switch ($json["app"]) {
case "localizoom":
$token_params = http_build_query(array(
"grant_type" => "authorization_code",
"code" => filter_input(INPUT_GET, "code"),
"redirect_uri" => getenv("ebrains_redirect_lz"),
"client_id" => getenv("ebrains_id_lz"),
"client_secret" => getenv("ebrains_secret_lz")
));
break;
case "webwarp":
$token_params = http_build_query(array(
"grant_type" => "authorization_code",
"code" => filter_input(INPUT_GET, "code"),
"redirect_uri" => getenv("ebrains_redirect_ww"),
"client_id" => getenv("ebrains_id_ww"),
"client_secret" => getenv("ebrains_secret_ww")
));
break;
}
$token_ch = curl_init(getenv("ebrains_token"));
curl_setopt_array($token_ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $token_params
));
$token_res = curl_exec($token_ch);
curl_close($token_ch);
$token_obj = json_decode($token_res, true);
$token = $token_obj["access_token"];
$json["token"] = $token;
?>
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="dppick.js"></script>
<script>
let state=<?php echo json_encode($json);?>;
async function startup(){
if(state.hasOwnProperty("filename")){
state.embedded=true;
location.href="filmstripzoom.html?"+encodeURIComponent(JSON.stringify(state));
return;
}
const choice=await dppick({
bucket:state["clb-collab-id"],
token:state.token,
title:`Select a ${{localizoom:"LocaliZoom",webwarp:"WebWarp"}[state.app]} descriptor`,
extensions:{webwarp:[".waln","wwrp"],localizoom:[".waln","wwrp","lz"]}[state.app],
nocancel:true
});
state.filename=choice.pick;
location.href="filmstripzoom.html?"+encodeURIComponent(JSON.stringify(state));
}
</script>
</head>
<body onload="startup()">
</body>
</html>