Forum Discussion
RyanS
Guide
Thanks for the information in this thread it got me all the info I needed to get this working in my PHP script.
I used the base snippet from the OP, but customized it to work with my needs.
I have incorporated SimpleXMLElement to handle the outputted XML response.
As you can see, I have stored the Status of the response in a local variable as well as the returned session key value.
Both of which, I intend to use in logical checks in my script's error checking and subsequent REST API calls, respectively.
----------------------------------------------------------------
<?php // Sets the external IP of the Server making the REST API calls $external_ip_address = '<your_external_ip(i.e.., xxx.xxx.xxx.xxx)>'; // Secret SSO key (128-bit or 256-bit) provided by Lithium $sso_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // Initialize Lithium SSO Client require_once("lithium_sso.php"); $lithium = new lithium_sso("<your company>", "<.your_company.com>", $sso_key); // (Optional) Additional user profile settings to pass to Lithium $settings_array = array(); $settings_array["roles.grant"] = "Administrator"; // Create the authentication token $liToken = $lithium->get_auth_token_value("<your_unique_id>", "<your_admin_username>", "<your_admin_email_address>", $settings_array, $lithium->get_server_var("HTTP_USER_AGENT"), $lithium->get_server_var("HTTP_REFERER"), $external_ip_address); $post_data="sso.authentication_token=$liToken"; $process = curl_init(); curl_setopt($process, CURLOPT_URL, 'http://<your_community>/<your_company>/restapi/vc/authentication/sessions/login'); curl_setopt($process, CURLOPT_TIMEOUT, 30); curl_setopt($process, CURLOPT_POST, 1); curl_setopt($process, CURLOPT_POSTFIELDS, $post_data); curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
$response = new SimpleXMLElement($return); echo 'response = ' . $response['status']; echo '<br>key = ' . $response->value; ?>
BradC
13 years agoKhoros Alumni (Retired)
Ryan, thanks for sharing your code snippet! I am glad to hear we were able to help you get up and running.
Related Content
- 4 years ago
- 2 years ago
- 13 years ago