Forums | Mahara Community

Developers /
Problems Oauth


Yolanda Mauri's profile picture
Posts: 3

18 April 2019, 5:29 AM

Hello everyone
I am trying to consume a mahara web service for getting a portfolio access with my LMS user authenticated. In Mahara wiki i found this code and I always get the same error : "IfaultCode 0 faultString A nonrecoverable error occurred. This probably means you have encountered a bug in the system".  Why? What I am doing wrong?
Best Regards.
See bellow please.

(I had to remove the "https" from URLs)

$options = array(
'consumer_key' => 'my_key',
'consumer_secret' => 'my_secret',
'server_uri' => 'mahara.local/webservice/rest/server.php',
'request_token_uri' => 'mahara.local/webservice/oauthv1.php/request_token',
'authorize_uri' => 'mahara.local/webservice/oauthv1.php/authorize',
'access_token_uri' => 'mahara.local/webservice/oauthv1.php/access_token',);
$store = OAuthStore::instance("Session", $options);
try {
// STEP 1: If we do not have an OAuth token yet, go get one
if (empty($_GET["oauth_token"]))
{
$getAuthTokenParams = array(
'xoauth_displayname' => 'Oauth test',
'oauth_callback' => 'lms.local'
);
$tokenResultParams = OAuthRequester::requestRequestToken($options['consumer_key'], 0, $getAuthTokenParams);
// In $tokenResultParams['token'] I get a token
// but in the next instruction I get the error message
header("Location: " . $options['authorize_uri'] . "?oauth_token=" . $tokenResultParams['token']);

}
else {
$oauthToken = $_GET["oauth_token"];
$tokenResultParams = $_GET;
try {
OAuthRequester::requestAccessToken($options['consumer_key'], $oauthToken, 0, 'POST', $_GET);
}
catch (OAuthException2 $e) {
var_dump($e);
return;
}
$secrets = $store->getSecretsForSignature($options["server_uri"], 1);
$body = '{"wsfunction":"mahara_user_get_users_by_id","users":[{"id":1}]}';
$request = new OAuthRequester($options['server_uri'].'?alt=json', 'POST', array(), $body);
$result = $request->doRequest(0);
if ($result['code'] == 200) {
var_dump($result['body']);
}
else {
echo 'Error';
}
}
}
catch(OAuthException2 $e) {
echo "OAuthException: " . $e->getMessage();
}
Kristina Hoeppner's profile picture
Posts: 3772

23 April 2019, 9:04 PM

Hi Yolanda,

What LMS do you want to connect to Mahara? We have instructions for setting up the connection for Moodle, Canvas, and Blackboard. See the user manual for more information. If you are using a different LMS, I'd be happy to check things out with you to add that LMS to our documentation. If your LMS supports LTI, you shouldn't have to set up web services for the authentication manually, but can use LTI.

Cheers

Kristina

Yolanda Mauri's profile picture
Posts: 3

25 April 2019, 3:24 AM

I'm programming this for a very small LMS we use in our institution. We programming a platform using Symfony 2.7. 

I am using OAuth library. So i need to do the LTI connection without any third party plugin.

The consumer i get can not change the request token for an access token. Then mahara throws this Exception: "IfaultCode 0 faultString A nonrecoverable error occurred. This probably means you have encountered a bug in the syste"

 Thank you.

Yolanda Mauri's profile picture
Posts: 3

25 April 2019, 9:17 AM

Hello Again:

I've been reviewed my source code and making some test. I need to login via LTI and then Mahara, so my LMS users must access to the portfolio directly. When I made this request:

<my-mahara-server>/webservice/oauthv1.php/authorize?oauth_token=f5dd4636ce6e38bb4636d10aacb8330005cc08eb5&oauth_callback=http%3A%2F%2Flocalhost%3A5804%2Fretorno.php%3Fconsumer_key%3De05ede9689c976cb8280e62da4030fea05cb74695%26usr_id%3D8

I get two errors:

  1. If there is a logged user, the error is:  faultCode 0 faultString A nonrecoverable error occurred. This probably means you have encountered a bug in the system
  2. If there is not a logged user, the error is: [WAR] d8 (lib\errors.php:535) [Error]: Call to a member function get() on unknown

Thanks for reading !

 

 

 

Robert Lyon's profile picture
Posts: 488

03 May 2019, 3:21 PM

Hi Yolanda,

I suspect for the:

'server_uri'
'request_token_uri'
'authorize_uri'
'access_token_uri'

You will need to prefix them with http://

Or on the bit:

header("Location: " . $options['authorize_uri'] . " ...

you will need to go

header("Location: http://" . $options['authorize_uri'] . " ...

As I don't think PHP header location works without indicating the URL schema part

Cheers

Robert

5 results