Skip to content
Snippets Groups Projects
Commit c32669f9 authored by Rasmus Fuhse's avatar Rasmus Fuhse
Browse files

debug

parent 23a16d4c
No related branches found
No related tags found
No related merge requests found
......@@ -65,10 +65,13 @@ class OAuth {
if ($owncloud[strlen($owncloud) - 1] !== "/") {
$owncloud .= "/";
}
$client_id = \Config::get()->OWNCLOUD_CLIENT_ID ?: \UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_CLIENT_ID; // The client ID assigned to you by the provider
$client_secret = \Config::get()->OWNCLOUD_CLIENT_SECRET ?: \UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_CLIENT_SECRET; // The client password assigned to you by the provider
$header = array();
$header[] = "Accept: application/json";
$header[] = "Authorization: Basic ".base64_encode($client_id . ":" .$client_secret);
$payload = array(
'grant_type' => "refresh_token",
......@@ -86,15 +89,18 @@ class OAuth {
curl_setopt($r, CURLOPT_POSTFIELDS, studip_utf8encode($payload));
$result = curl_exec($r);
$json = curl_exec($r);
curl_close($r);
$header_size = curl_getinfo($r, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = studip_utf8decode(json_decode(substr($result, $header_size)));
$json = studip_utf8decode(json_decode($json, true));
$config = \UserConfig::get($GLOBALS['user']->id);
$config->store("OWNCLOUD_ACCESS_TOKEN", $body['access_token']);
$config->store("OWNCLOUD_ACCESS_TOKEN_EXPIRES", time() + $body['expires_in']);
if ($json['error']) {
PageLayout::postError(_("Authentifizierungsfehler:")." ".$json['error']);
} else {
$config = \UserConfig::get($GLOBALS['user']->id);
$config->store("OWNCLOUD_ACCESS_TOKEN", $json['access_token']);
//$config->store("OWNCLOUD_REFRESH_TOKEN", $json['refresh_token']);
$config->store("OWNCLOUD_ACCESS_TOKEN_EXPIRES", time() + $json['expires_in']);
}
}
}
\ No newline at end of file
......@@ -9,10 +9,8 @@
<?= _("OwnCloud konfigurieren") ?>
</legend>
<? var_dump(\UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ACCESS_TOKEN) ?>
<? if (\Owncloud\OAuth::isReady()) : ?>
<?= MessageBox::info(_("OwnCloud-Rechte sind freigegeben")) ?>
<?= MessageBox::info(_("OwnCloud ist verknpft")) ?>
<? elseif(UserConfig::get($GLOBALS['user']->id)->OWNCLOUD_ENDPOINT) : ?>
<div style="text-align: center;">
<?= \Studip\LinkButton::create(_("OwnCloud fr Stud.IP freigeben"), PluginEngine::getURL($plugin, array(), "oauth/request_access_token")) ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment