Moodle plugins directory: Oauth2 authentication plugin for Moodle (for Moodle 3.2 and earlier) | Moodle.org
Oauth2 authentication plugin for Moodle (for Moodle 3.2 and earlier)
Plugin end of life starting from Moodle 3.3
starting from Moodle 3.3, Oauth2 should be implemented in Moodle core. It will require you to upgrade to Moodle 3.3 and switch to the Oauth2 core authentication (and probably do some migration), but it is a great news as authentication is a really sensible matter and having Oauth2 plugins in core will guarantee their maintenance. So starting from Moodle 3.3 I highly recommend to use the new Oauth2 core plugins ((https://docs.moodle.org/dev/Better_Office_Integrations_3.3#Core_API_for_managing_Authorized_OAuth_Applications) ) . Missing core providers will likely be implemented by someone and published in the Moodle.org plugin repository. There will probably be a new Oauth2 category in the Moodle plugin repository. Wait and see...
I will try to mantain this plugin until Moodle 3.1 (LTS) runs out of security upport (13 May 2019).
Warning for Facebook users
The plugin stopped working the 27th March 2017 as Facebook closed the API 2.2. The last versions of this plugin have been updated to support Facebook 2.8 API. As usual carefully test before upgrading a third party plugin if your Moodle site is important to you (especially as it is an authentication plugin)
Installation
- add the plugin into /auth/googleoauth2/
- in the Moodle administration, enable the plugin (Admin block > Plugins > Authentication)
- in the plugin admin page, follow the displayed instructions.
I also created a free mini-course on how to install a Moodle plugin using Oauth2 plugin as example.
Documentation and support
You can search in all existing issues on Github. Go to the issues page, next to the filter button there is a search field. Remove the default content, type your keywords and press enter.
There is a FAQ too.
Alternative plugins
There are many alternatives to this plugin, if you have any trouble with this plugin it may be a good idea to try them:
- Moodle core Oauth2 plugins (Moodle 3.3 and later)
- Elcentra
- LenAuth
- OpenID Connect
- LinkedinAuth
- check the auth plugin list
I changed only one line in googleauth2/auth.php
instead
294 $user = authenticate_user_login($username, null);
-> $user = get_complete_user_data('username', $username, $CFG->mnet_localhost_id);
profit!
'The authentication provider sent us a communication error. Please try to sign-in again.' - this is related to the $string['couldnotgetgoogleaccesstoken']
I Have tried signing in numerous times and checked my Google API key and other settings.
Could you suggest why I would be getting this error? and how I could potentially resolve it?
I think I've configured all settings within the authentication section for admins, I also installed the moodlebook theme but I can't get to have the auth login option anywhere… what am I missing?
I read that I should include some php code but couldn't find the file where it should go maybe it's not named that way on my version?
I found this link: http://stackoverflow.com/questions/10858813/restrict-login-email-with-google-oauth2-0-to-specific-domain-name
But don't know how to customize in our case.
Except for one thing:
I have installed both facebook and google+, and with that I got a small problem.
When entering the login screen for the first time, both of the login methods are shown. If I choose Facebook, and login and out again (and make sure I have also logged out of my facebook-session), and return to the login-screen, I can only see one of the login methods.
There is a link "Sign-in with another service" at the bottom, but it doesn't bring up both of the login methods, because it points wrong. It puts the ?allauthproviders=true directly to the main moodle address, without adding the /login/index.php inbetween.
It seems to me that some variable is not validated correctly, so the "/login/index.php" is not added:
./theme/base/layout/login.php:
echo $CFG->wwwroot . (isset($CFG->alternateloginurl) ? $CFG->alternateloginurl : '/login/index.php') . '?allauthproviders=true';
error/facebook_failure
Debug info:
Error code: facebook_failure
$a contents:
Stack trace:
line 11 of /auth/googleoauth2/facebook_redirect.php: moodle_exception thrown
Why???? Please Help meeeeeeeeeee!!!!
It seems it refreshes back to Login after loggin in? Could u see whats up? Its 2.5
So in your login page html the line will be something like
https://accounts.google.com/o/oauth2/auth?hd=domain.com&client_id=<?php echo get_config('auth/googleoauth2', 'googleclientid'); ?>&redirect_uri=<?php echo $CFG->wwwroot; ?>/auth/googleoauth2/google_redirect.php&scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email&response_type=code">Sign in with Google
I want to use our google apps domain accounts to login to moodle. I have set up this plugin following the instructions but when I click on the "Login with Google" link It prompts me to login to google, which I do but then I get redirected back to the moodle login page asking me for a username and password.
Do I need to disable other login methods for this to work??
I currently authenticate against LDAP and also have the Google SAML plugin enabled. Would this cause any issues?