config->url; //$url = 'https://demo.clickedu.eu/ws/moodle_clickedu_init.php'; $url = $url_original.'/ws/moodle_clickedu_init.php'; // Obtenir el valor de la url $config = array( 'consumer_key' => $CFG->oauth_consumer, 'consumer_secret' => $CFG->oauth_consumer_secret, 'host' => $url, 'use_ssl' => false, // Change this on production ); $oauth = new tmhOAuth( $config ); $code = $oauth->apponly_request(array( 'without_bearer' => true, 'method' => 'POST', 'url' => $url, 'params' => array( 'oauth_callback' => $_SERVER['REQUEST_URI'], ), )); // ORIGINAL /* $code = $oauth->apponly_request(array( 'without_bearer' => true, 'method' => 'POST', 'url' => $oauth->url('ws/oauth/request_token', ''), 'params' => array( 'oauth_callback' => $_SERVER['REQUEST_URI'], ), )); */ try{ if( $code != 200 ) throw new Exception( "No s'ha pogut obtenir un token correcte" ); $valid = true; $ret_info = $oauth->extract_params( $oauth->response['response'] ); // Per la versi� >2.0, set_config retorna booleans per indicar si ha funcionat correctament la crida. // En la versi� <2.0, retorna un mixed molt mixed bastant inesperat, per tant, es tracta diferent. $ret_at = set_config( 'access_token', $ret_info['token'] ); $ret_as = set_config( 'access_secret', $ret_info['secret'] ); if( ES_MOODLE_20 ) { $valid |= $ret_at; $valid |= $ret_as; } else { $valid |= !empty( $ret_at ); $valid |= !empty( $ret_as ); } if( !$valid ) throw new Exception( "No s'ha pogut emmagatzemar correctament l'access token i el secret" ); ?>