Authenticate external app against Moodle login

Authenticate external app against Moodle login

by Albert Leatherman -
Number of replies: 8

Hi, is it possible for an external app or site to check to see if the email and password entered by a user matches the user's Moodle login information? Can Moodle return some kind of Boolean yes/no to the external app/site? Thanks.

Average of ratings: -
In reply to Albert Leatherman

Re: Authenticate external app against Moodle login

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It's possible. You'd need to write a plugin to do it. 

In reply to Howard Miller

Re: Authenticate external app against Moodle login

by Albert Leatherman -

Thanks a lot Howard. Do you know if any similar plugins already exist?

In reply to Albert Leatherman

Re: Authenticate external app against Moodle login

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I would probably write this as a local plugin that created a new web service. 

So - https://docs.moodle.org/dev/Local_plugins

https://docs.moodle.org/dev/Web_services

Essentially, you're calling the authentication code in Moodle to see if a user is valid. Check out the manual authentication plugin in /auth/manual to see how it does it. The exciting lines are...

        if (!$user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
            return false;
        }
        if (!validate_internal_user_password($user, $password)) {
            return false;
        }


In your case, you'd be looking up the user record from the email address. 

Average of ratings: Useful (1)
In reply to Howard Miller

Re: Authenticate external app against Moodle login

by Hardik Mashru -

Hi Howard,

Thanks for the response. I have tried creating a simple hello world plugin and install it into my local plugins and given all the necessary permissions and I am having a hard time get it working.  I am not sure what I am doing wrong but I followed every instructions as mentioned regarding permissions and user role etc but I still cannot get it working. I tried with hello_world method first so that at least I can check if the web service works or not. 

Could you please look at this example and help me find out what is wrong with the code


https://github.com/moodlehq/moodle-local_wstemplate


Thanks, I really appreciate your help on this

In reply to Hardik Mashru

Re: Authenticate external app against Moodle login

by Daniel Neis Araujo -
Picture of Core developers Picture of Plugin developers Picture of Translators

Hello,


it may be simpler to use token.php (https://github.com/moodle/moodle/blob/master/login/token.php) just like the mobile app does.

In reply to Daniel Neis Araujo

Re: Authenticate external app against Moodle login

by Hardik Mashru -

I just want to validate the username and password using the web service. I don' want to use any other functionalities by moodle. Any suggestion?

In reply to Daniel Neis Araujo

Re: Authenticate external app against Moodle login

by Hardik Mashru -

Hi Daniel,

Thanks for referring to this file on github. Now to call this php file and get the response from it what would I need to do? install a plugin or anything? or just call this url ? enable something from moodle? I am sorry for too many questions as I am just mobile app developer so I have no clue about Moodle things.

I really appreciate your help.


Thanks