Authentication API

Install and configure FormaLMS and DoceboCE
Post Reply
kthroc23
Newbie
Posts: 8
Joined: Sat Nov 23, 2019 12:35 am

Authentication API

Post by kthroc23 »

Can anyone help with the Authentication API with the new version 4.0.7?

I have a simple php website that I want to authenticate users by the API of Forma. I have followed the documentation and still does not work.
alfa24
Senior Boarder
Posts: 2031
Joined: Fri Nov 24, 2017 8:45 am

Re: Authentication API

Post by alfa24 »

Hi, you should provide more details. Code used to achieve the auth, what errors do you get, and so on.
Per supporto GRATUITO contattatemi in privato qui
kthroc23
Newbie
Posts: 8
Joined: Sat Nov 23, 2019 12:35 am

Re: Authentication API

Post by kthroc23 »

This is my simple code below. Is my API call correct? Also, this code worked for FORMA 2.3.0. I am not sure if anything changed.

Code: Select all

   $params = array("username"=>'test@test.com', "password"=>'password');
    $key = "testtesttest";
    $secret = "password";

    $codice_sha1 = strtolower(sha1(implode(',', $params) . ',' . $secret));
    $codice = base64_encode($key . ":" . $codice_sha1);

    $curl = curl_init();

    curl_setopt_array($curl,  array(

        CURLOPT_URL => "https://lms.mylms.com/api/auth/authenticate",
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $params,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            "X-Authorization: FormaLMS " . $codice,
        ],
    ));

    $response = curl_exec($curl);
    $error = curl_error($curl);

    curl_close($curl);

    $xml = simplexml_load_string($response);

    $json = json_encode($xml);
    $array = json_decode($json,TRUE);

    echo json_encode($array);



alfa24
Senior Boarder
Posts: 2031
Joined: Fri Nov 24, 2017 8:45 am

Re: Authentication API

Post by alfa24 »

What do you obtain?
I mean, $response and/or $error ?
Per supporto GRATUITO contattatemi in privato qui
kthroc23
Newbie
Posts: 8
Joined: Sat Nov 23, 2019 12:35 am

Re: Authentication API

Post by kthroc23 »

The response data is the 404 server error saying that File or directory not found.
alfa24
Senior Boarder
Posts: 2031
Joined: Fri Nov 24, 2017 8:45 am

Re: Authentication API

Post by alfa24 »

It's the URL to be call correct? I suppose it's not https://lms.mylms.com/api/auth/authenticate...
If you're not able to debug such an easy problem, I'd suggest to hire a developer or you'll risk more serious issues.
Per supporto GRATUITO contattatemi in privato qui
kthroc23
Newbie
Posts: 8
Joined: Sat Nov 23, 2019 12:35 am

Re: Authentication API

Post by kthroc23 »

Can you or anyone show me a simple url for the API call?

For Forma version 4.0.7, Which of the follow should be the API url to check for username?

a) lms.forma.com/api/user/checkUsername

b) lms.forma.com/api/rest.php?q=/api/user/checkUsername

or

c) please provide an example URL call to the the rest api.
alfa24
Senior Boarder
Posts: 2031
Joined: Fri Nov 24, 2017 8:45 am

Re: Authentication API

Post by alfa24 »

If your Forma instance is installed in https://lms.mylms.com/, your CURLOPT_URL should be https://lms.mylms.com/api/rest.php?q=/a ... thenticate
Per supporto GRATUITO contattatemi in privato qui
Post Reply