Page 1 of 1

API Authentication

Posted: Wed Jun 03, 2020 2:01 pm
by Rival
Hi,

Let me start by saying I can just about read PHP code. I got somebody to write some PHP code for formaLMS's API. (This person is no longer available to help me.) :cry:

For the most part, the code is working beautifully. I do however need help securing this with a token. Can somebody explain how to modify the below code and how to set it up in the LMS's API Authentication method?

I did read the new API documentation but I can't figure it out.
Here is the code I got. Any help would be greatly appreciated.

Code: Select all

<?php

$url = "https://demo.formalms.com:443/";
$action = 'user/updateuser';

$data_params = array('idst' => 11836, 'lastname' => 'Doe');
						   
                 $curl = curl_init();

                 $opt = array(
                         CURLOPT_URL=>$url.'/api/'.$action,
                         CURLOPT_RETURNTRANSFER=>1,
                         CURLOPT_POST=>1,
                         CURLOPT_POSTFIELDS=>$data_params,
                         CURLOPT_CONNECTTIMEOUT=>5, // Timeout to 5 seconds
                         CURLOPT_SSL_VERIFYPEER => 'false',
                         );

                 curl_setopt_array($curl, $opt);

// $output contains the output string

                 $output = curl_exec($curl);

// it closes the session

                 curl_close($curl);

                 echo $output;

Re: API Authentication

Posted: Wed Jun 03, 2020 6:47 pm
by alfa24
What kind of token?
Can you be more specific?

Re: API Authentication

Posted: Wed Jun 03, 2020 7:55 pm
by Rival
Hi,

I am not sure what token/setup to use to make the API more secure. In the LMS under API settings you can specify "Token generation at every connection" or "Authorisation Secret Key". Or should I specify a random string in the textbox? But then how do I reference this string in the API code. Like I said I am not sure how to secure the API interface so that not every Tom Dick and Harry can use the API once enabled.

Image

Re: API Authentication

Posted: Wed Jun 03, 2020 8:07 pm
by alfa24
So you only need the API work with the provided token. If you can't find it out with the docs, feel free to write me privately and I'll help to develop your own API layer.