Forums/Community/Community tips & tricks

PHP Remote authentication via Moodle

Chrismegahan
posted this on October 14, 2011 07:21

No Moodle site is complete without a proper support system. For those of us supporting hundreds or thousands of users, a real help desk software is a must. I quickly put this together to tie authentication for Zendesk into Moodle. I hope someone else might find it useful for their site.

 

Comments

User photo
Mountain/\Ash
atmail

I had to turn it off as customers can not use Zendesk as they would expect until we get this working. Can you investigate our code anyway?

August 08, 2012 21:56
User photo
Christopher Megahan

Sure Rowan, whats the problem?

August 09, 2012 09:45
User photo
Jury Belonozhkin

Hi, Christopher!
Please explain me what i must to do for SSO in  Zendesk from Moodle? 
Thanks for advance! 

August 20, 2012 09:29
User photo
Christopher Megahan

The instructions are in the comments of the PHP file. You will need to edit the file with your moodle config path, zendesk authentication token and zendesk.com subdomain of your help desk.

August 20, 2012 09:40
User photo
Jury Belonozhkin

Thank you, Christopher!

I can edit your file. But where i must put it? In root moodle directory?

August 20, 2012 09:48
User photo
Christopher Megahan

Put in in your Moodle root directory. Enable single sign on in Zendesk, specify the login url... yourdomain.com/moodle/zendesk_auth.php and your logout URL yourdomain.com/moodle/login/logout.php also check "Allow update of external ids?". You will also need to generate a token to paste in the script.

August 20, 2012 10:12
User photo
Christopher Megahan

I should mention... I have used this script for 9+ months on a Moodle 1.9 site but have yet to try it with v2.0+. If it doesn't work I will re-write this when my company upgrades to the latest version.

August 20, 2012 12:29
User photo
Jury Belonozhkin

Christopher,
i use Moodle 1.9. 
See please screencast of my actions here https://docs.google.com/file/d/0ByF5MrdoU8-4VHFNQW44dVRNOUU/preview
My SSO don't work. First name and lastname of registred Moodle users are not inserted automaticaly in new ticket. What i've made wrong? Please help me.

August 20, 2012 21:28
User photo
Jury Belonozhkin

Dear Christopher,
must i explain my problem more clear? Please help me. 

August 23, 2012 02:19
User photo
Christopher Megahan

For example if your zendesk url is "moodleuniversity.zendesk.com" your prefix would be "moodleuniversity".

$sUrlPrefix = "moodleuniversity"; 

 

Try removing the ".zendesk.com" from the sUrlPrefix.

August 23, 2012 06:22
User photo
Christopher Megahan

Also, this is "Single Sign On" for the helpdesk and SSO doesn't work with the dropbox. To get around this I added the attached code to the header of my Moodle theme... edit your existing dropbox and add these two lines like the example.

requester_name: '<?php echo $USER->firstname.' '. $USER->lastname; ?>',
requester_email: "<?php echo $USER->email; ?>",

August 23, 2012 06:36
User photo
Jury Belonozhkin

Christopher,
i've tryed, but not successfull. See please attach. 

August 23, 2012 06:38
User photo
Christopher Megahan

You didn't update the Moodle config file path per the instructions in the comments. You must insert the location of the config file.

This is usually something like /var/www/config.php or /username/public_html/config.php

August 23, 2012 06:46
User photo
Jury Belonozhkin

I probed (see attach). 

I'm not programmer, that's why not make all correct. Any ideas?

August 23, 2012 07:04
User photo
Christopher Megahan

Try this.. did a work around since you don't know what the file path is.

August 23, 2012 07:16
User photo
Christopher Megahan

Also, change your token... posting it in the public can be very dangerous.

August 23, 2012 07:16
User photo
Jury Belonozhkin
August 23, 2012 08:09
User photo
Christopher Megahan

change your first line to 

require_once(dirname(__FILE__).'/config.php');

or

 require_once(/var/www/vds670/data/www/e.sutr.ru/config.php)

August 23, 2012 08:18
User photo
Jury Belonozhkin

After edditing as

<?php
/* Insert path to Moodle config here */
require_once('/var/www/vds670/data/www/e.sutr.ru/config.php');
require_login();

i suddenly see "Do you really want to logout?" on my site http://e.sutr.ru/login/logout.php?message=Invalid+token+for+remote+authentication%2C+check+that+your+security+token+is+up+to+date&kind=error

I can't edit my token while can't to login in https://sochistateuniversity.zendesk.com/ as admin.

August 23, 2012 08:28
User photo
Christopher Megahan

you must have reversed the "Remote login URL" and "Remote logout URL" under your zendesk security settings...

August 23, 2012 08:31
User photo
Jury Belonozhkin

I can not to login as admin to https://sochistateuniversity.zendesk.com/home. My rights are lost. https://sochistateuniversity.zendesk.com/home is now broken.

August 23, 2012 08:35
User photo
Christopher Megahan

Try the normal login which bypasses sing sign on.

https://sochistateuniversity.zendesk.com/access/normal

August 23, 2012 08:37
User photo
Jury Belonozhkin

After reseting my PC it's allowed me to login in https://sochistateuniversity.zendesk.com as admin. I'm very glad!
I'v changed token. Please see my php-file what is wrong. (Later i'll change token).

Are my "Remote login URL" and "Remote logout URL" correct? (attach) 

August 23, 2012 09:39
User photo
Jury Belonozhkin

Dear Christopher,

i probed make all your recomendations here https://docs.google.com/file/d/0ByF5MrdoU8-4TmhNTFdFc3pERGM/edit?pli=1 (sorry for bed microfon and speaking). Please see my attempt, what i must to do for that wonder SSO?

August 24, 2012 02:51
User photo
Jury Belonozhkin

Christopher,
perhaps it would be more faster explain this in your screencast? What habe you done in your moodle site in visual? 

August 24, 2012 02:56
User photo
Jury Belonozhkin

My problem is ressolved. Details are here http://moodle.org/mod/forum/discuss.php?d=188113#p914621

August 25, 2012 03:06
User photo
Dan Olson
learningmarkets

HI Chris,

This looks great, but we just tried to implement this and followed your instructions on the Moodle forums and it doesn't want to work. Is the php file attached here the latest version?
Thanks,

Dan

 

May 15, 2013 09:55
User photo
Christopher Megahan

Dan,

Send me an email with what Moodle version you are using and I'll try to help you out. cbmegahan@geeksmith.com

May 15, 2013 09:58