api forma23

Installazione, configurazione generale, notifiche, API, lingue, problemi server
alfa24
Senior Boarder
Posts: 2009
Joined: Fri Nov 24, 2017 8:45 am

Re: api forma23

Post by alfa24 »

Prova a sotituire:

if(!(new self())->checkAuthentication($auth_code)) {
return false;
}

con:

$_api_instance = new self();
if(!($_api_instance->checkAuthentication($auth_code))) {
return false;
}
Per supporto GRATUITO contattatemi in privato qui
d.ravasco
FormaLms User
Posts: 99
Joined: Tue Apr 18, 2017 3:56 pm
Version: forma.lms 2.0

Re: api forma23

Post by d.ravasco »

Ancora nulla.
il var_dump restituisce questo messaggio
object(SimpleXMLElement)#1 (1) { ["error"]=> object(SimpleXMLElement)#2 (0) { } }
invece di
object(SimpleXMLElement)#1 (1) { ["error"]=> string(20) "Error: invalid user." }
alfa24
Senior Boarder
Posts: 2009
Joined: Fri Nov 24, 2017 8:45 am

Re: api forma23

Post by alfa24 »

Se provi ad attivare il debug intercetti qualche errore prima del var_dump?
Per supporto GRATUITO contattatemi in privato qui
d.ravasco
FormaLms User
Posts: 99
Joined: Tue Apr 18, 2017 3:56 pm
Version: forma.lms 2.0

Re: api forma23

Post by d.ravasco »

sono già attive le istruzioni per il debug ma non intercetta nulla
error_reporting(E_ALL);
ini_set( 'display_errors', 1 );

cmq per oggi passo e vedo di continuare a fare qualche altro test nei prossimi giorni. Grazie per l'aiuto
mriva
Newbie
Posts: 3
Joined: Sun Feb 23, 2020 12:03 am
Version: forma.lms 2.4

Re: api forma23

Post by mriva »

È passato un po' di tempo dall'ultima risposta, ma visto che mi sono appena scontrato con questo bug, riporto la mia esperienza.

Il problema dell'autenticazione tramite token è che il codice di lms forma fa la checkAuthentication() anche sulla chiamata /api/auth/authenticate; ovviamente così non funziona perché il codice richiede di essere autenticati per fare l'autenticazione... è il cane che si morde la coda. In generale gli endpoint di autenticazione (quelli a cui inviare user e password) devono essere per ovvie ragioni pubbliche, o per lo meno non protette dallo stesso tipo di autenticazione che devono fornire.
mriva
Newbie
Posts: 3
Joined: Sun Feb 23, 2020 12:03 am
Version: forma.lms 2.4

Re: api forma23

Post by mriva »

La modifica che sto testando è passare (nel file 'api/lib/lib.api.php') da queste righe:

Code: Select all

static public function Execute($auth_code, $module, $function, $params) {

    if(!(new self())->checkAuthentication($auth_code)) {
        return false;
    }
    ...
a queste

Code: Select all

public static function Execute($auth_code, $module, $function, $params) {
    $api_call = "{$module}/{$function}";
    if ($api_call != 'auth/authenticate' && !(new self())->checkAuthentication($auth_code)) {
        return false;
    }
    ...
Post Reply