Skip to content

Instantly share code, notes, and snippets.

@pitbulk
Last active March 17, 2017 16:05
Show Gist options
  • Save pitbulk/59f4e046a4ccb3441c7a04f8c7652785 to your computer and use it in GitHub Desktop.
Save pitbulk/59f4e046a4ccb3441c7a04f8c7652785 to your computer and use it in GitHub Desktop.
Onelogin - Embed Apps API
<?php
// URL & credentials
$url = "https://api.onelogin.com/client/apps/embed2";
// Parameters
$embed_token = "<embed_token>";
$email = "<email>";
$query_parameters = array(
'token' => $embed_token,
'email' => $email
);
$query = http_build_query(array_filter($query_parameters));
if (!empty($query)) {
$url .= '?' . $query;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
if ($result !== false) {
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$body = substr($result, $header_size);
$xml_apps_info = $body;
$xml = simplexml_load_string($xml_apps_info);
$json = json_encode($xml);
$apps_info = json_decode($json, true);
if (array_key_exists('app', $apps_info)) {
if (count($apps_info['app']) == 1) {
$app = $apps_info['app'];
echo 'APP: <a href="https://app.onelogin.com/launch/'.$app['id'].'">'.$app['name'].'<img src="'.$app['icon'].'" ></li>';
} else {
echo 'Lit of apps:';
echo '<table boder="0">';
foreach ($apps_info['app'] as $app) {
echo '<tr><td><a href="https://app.onelogin.com/launch/'.$app['id'].'">'.$app['name'].'</td><td><img src="'.$app['icon'].'" ></td></tr>';
}
echo '</table>';
}
}
} else {
throw new Exception(curl_error($ch), curl_errno($ch));
}
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment