Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Single signon with Moodle

Hello all, In case you don't know, the moodle forums are very basic with little structure or control, so I've set up Vanilla to display embedded in the Moodle site - all working fine.
What I'm struggling with is implementing a single sign on via the existing site. I've read the jsConnect page here but, since I have a fairly basic understanding of how these things work, I'm unsure what I actually need to do.
I'd really appreciate any pointers on where functions.jsconnect.php and index.php need to go. Vanilla forums is hosted at a different domain to the Moodle site at the moment although that will probably change in time.
Thanks in advance...

«1

Comments

  • businessdadbusinessdad Stealth contributor MVP

    I think that the easiest way would be developing a Moodle plugin for it.

  • Sadly that's well outside my capabilities!!

  • businessdadbusinessdad Stealth contributor MVP

    I would probably be able to develop a Moodle plugin, but, unfortunately, my list is full at the moment. I can take note of it and, eventually, see what I can do when I'll have some spare time.

  • Now that would be fabulous - thanks! In the meantime I'll keep tinkering.

  • We have just downloaded Vanilla and are exploring ways to connect it to our Moodle courses. Have either of you learned anything since you last posted here? Still no plugins available on Moodle, as far as I know. But someone did develop a plugin for Vanilla that creates an LTI connection. Not exactly sure how that works with Moodle -- but there's a post in the Moodle forums about it here.

  • businessdadbusinessdad Stealth contributor MVP

    I haven't looked at it yet, due to other commitments. The logic itself is not too complicated, but I would have to learn how to transform it into a Moodle plugin.

  • edited August 2013

    Well, believe it or not, I'm still struggling with this. Since my last post I've installed Vanilla on the same server as my Moodle install, I have jsconnect installed and properly (I think) configured and have functions.jsconnect.php and index.php (the latter renamed to sso.php) in the root web directory.

    My sso.php looks like this:

    <?php
    require_once dirname(__FILE__).'/functions.jsconnect.php';
    
    // 1. Get your client ID and secret here. These must match those in your jsConnect settings.  
    $clientID = "1234567890";
    $secret = "123a7d14b97e624cbc75d1b228c2fbba";
    
    // 2. Grab the current user from your session management system or database 
    $signedIn = true; // this is just a placeholder
    
    // YOUR CODE HERE.
    
    // 3. Fill in the user information in a way that Vanilla can understand.
    $user = array();
    
    if ($signedIn) {
    // CHANGE THESE FOUR LINES.
    $user['uniqueid'] = $USER->id;
    $user['name'] = $USER->username;
    $user['email'] = $USER->email;
    $user['photourl'] = '';
    }
    
    // 4. Generate the jsConnect string.
    
    // This should be true unless you are testing.·
    // You can also use a hash name like md5, sha1 etc which must be the name as
    $secure = true;·
    WriteJsConnect($user, $_GET, $clientID, $secret, $secure);
    

    When I test the jsConnect settings in the dashboard I get:

    test({"email":"","name":"","photourl":"","uniqueid":"","client_id":"1234567890","signature":"370e258aabff177244f19b4dfca0d630"})

    so it's clearly not picking up the id, username and email?
    My head is about to explode! Please can anybody spot what I'm doing wrong?
    Thanks

  • ShadowdareShadowdare r_j MVP
    edited August 2013

    Lines 18-21: is $USER declared? Add var_dump($USER); before the conditional to see if it is.

    Line 24: 4. Generate the jsConnect string. should be commented or removed.

    Add Pages to Vanilla with the Basic Pages app

  • Line 24 is commented out, cut and paste went wrong - fixed above!
    I really am a beginner at all of this, do you mean var_dump($USER); should go in after line 16?

  • It can go anywhere within the lines that you pasted and preferably on line 15, which is before the if statement.

    Add Pages to Vanilla with the Basic Pages app

  • hgtonighthgtonight ∞ · New Moderator
    edited August 2013

    You need to get the Moodle session and use that to fill out the $USER object.

    EDIT: It looks like Moodle stores the user object in a super global. Try adding global $USER; to the top of your file (after the initial PHP tag). SOURCE

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @hgtonight said:
    You need to get the Moodle session and use that to fill out the $USER object.

    EDIT: It looks like Moodle stores the user object in a super global. Try adding global $USER; to the top of your file (after the initial PHP tag).

    Tried adding global $USER; but still the same output from 'test connection' - any other ideas?

  • hgtonighthgtonight ∞ · New Moderator

    Try putting this before your global user line:

    require "../path/to/config.php";
    
    require_login();
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @Shadowdare said:
    It can go anywhere within the lines that you pasted and preferably on line 15, which is before the if statement.

    Just tried this and test connection is displaying NULL followed by the previous (empty) output?

  • @hgtonight said:
    Try putting this before your global user line:

    require "../path/to/config.php";
    
    require_login();
    

    Nothing displaying at all - v frustrating!

  • It's confirmed that $USER isn't declared. You need to retrieve the user session object as $USER from Moodle and require it in your script as @hgtonight said.

    Add Pages to Vanilla with the Basic Pages app

  • @Shadowdare said:
    It's confirmed that $USER isn't declared. You need to retrieve the user session object as $USER from Moodle and require it in your script as hgtonight said.

    The snag is that I'm stumbling about here and don't really understand how to do that.

  • ShadowdareShadowdare r_j MVP
    edited August 2013

    Put this at the top of your script on a new line under <?php and replace the path in the require statement to the config.php file of your Moodle install:

    require('/path/to/moodleconfig/config.php');
    
    require_login();
    
    global $USER;
    

    Then do this: https://moodle.org/mod/forum/discuss.php?d=187465#yui_3_9_1_2_1377796314235_261

    Add Pages to Vanilla with the Basic Pages app

  • @Shadowdare said:
    Put this at the top of your script on a new line under <?php and replace the path in the require statement to the config.php file of your Moodle install:

    require('/path/to/moodleconfig/config.php');
    
    require_login();
    
    global $USER;
    

    Then do this: https://moodle.org/mod/forum/discuss.php?d=187465#yui_3_9_1_2_1377796314235_261

    You're a star!! All working fine now - excellent.
    For some reason, the '/path/to/moodleconfig/config.php' needed to be the absolute path on the server not just a relative one which is what I tried when you first suggested it.
    I'll post up the config files tomorrow in case anybody else runs into the same problem.
    Once again, many thanks.

  • No problem! Thanks to @hgtonight for actually finding the link for the solution!

    Add Pages to Vanilla with the Basic Pages app

Sign In or Register to comment.