Error fetching OAuth2 access token

Error fetching OAuth2 access token

by michael mckenzie -
Number of replies: 13

I am trying to setup Google Drive Repository.


I have followed all instructions, but when i try to authorise the access I get:

Armidale High School Moodle 2.8

Exception - Error fetching OAuth2 access token, message: ''

More information about this error

Debug info: 
Error code: generalexceptionmessage
Stack trace:
  • line 124 of /lib/google/Google/Auth/OAuth2.php: Google_Auth_Exception thrown
  • line 130 of /lib/google/Google/Client.php: call to Google_Auth_OAuth2->authenticate()
  • line 121 of /repository/googledocs/lib.php: call to Google_Client->authenticate()
  • line 62 of /repository/repository_callback.php: call to repository_googledocs->callback()
Output buffer: <br /> <b>Notice</b>: Undefined offset: 1 in <b>/srv/www/moodle2_new/lib/google/Google/IO/Abstract.php</b> on line <b>274</b><br />


I have double checked as much as I can,


Any help would be appreciated


Average of ratings: -
In reply to michael mckenzie

Re: Error fetching OAuth2 access token

by Karen Williams -

I'm getting almost the exact same error. Mine is different in the output buffer, I have an undefined variable "errorText"

Any help would be much appreciated

Thanks

Karen

Attachment Google_Drive.JPG
In reply to michael mckenzie

Re: Error fetching OAuth2 access token

by Rachel Epler -

I am also having this issue, as shown below.  Have you found a resolve for this?  I just updated Moodle to see if any of the latest patches addressed this without any luck.  Any help is appreciated!


Exception - Error fetching OAuth2 access token, message: ''

More information about this error

Debug info: 

Error code: generalexceptionmessage

Stack trace:

  • line 124 of /lib/google/Google/Auth/OAuth2.php: Google_Auth_Exception thrown
  • line 130 of /lib/google/Google/Client.php: call to Google_Auth_OAuth2->authenticate()
  • line 121 of /repository/googledocs/lib.php: call to Google_Client->authenticate()
  • line 62 of /repository/repository_callback.php: call to repository_googledocs->callback()

In reply to Rachel Epler

Re: Error fetching OAuth2 access token

by Ken Task -
Picture of Particularly helpful Moodlers

IF ... am correct ... this might apply to all posters in this thread ...

Moodle versions 2.8 and 2.9 have been dated/fixed IF you have the latest updates to those versions.  Moodle 2.7 and lower, however, is/are broke (but there is a additional addon provided in these forums to fix the 2.7 issue).  Maybe someone can find it again and provide the link. :|

So here's an example of a 2.8 ...

Google Drive for sos.tcea.org/moodle28/

http://docs.moodle.org/28/en/Google_OAuth_2.0_setup
which tells you to go to:
https://console.developers.google.com

Google has changed some things so you need to locate the Credentials you
created for your Moodle.   Won't be named for your Moodle.  If you have more than
one, like I do, you'll see a listing of sites under 'OAuth 2.0 client ID's'
like web site 1, web site 2, etc.   Only way to know, click into one and look
for the 'call back' URL to your site ... that's what changed a little.

As part of the registration process, you will need to enter the following URL as 'Authorized Redirect URIs':

http://yoursite/admin/oauth2callback.php

Once registered, you will be provided with a client ID and secret which can be used to configure all Google Drive and Picasa plugins.

Please also note that you will have to enable the service 'Drive API'.

Example For a Moodle 28 Oauth

Javascript origins
http://site (no trailing slash)

Authorized redirect URL's:
http://site/moodle28/auth/googleoauth2/google_redirect.php

Copy the ClientID and Client Secret to a notepad text file for keeping.

Then go back to your config for google Drive repo
and insert the updated/changed? ClientID and Client Secret

Once saved ... try it again.

** don't copy the above lines and paste them verbatum**  Copy lines only from your site and Google screens.

'spirit of sharing', Ken

In reply to Ken Task

Re: Error fetching OAuth2 access token

by Rachel Epler -

Thanks, Ken.  I really appreciate your time and energy for the post.  Unfortunately, still did not resolve the issue.  :/

I'm going to search for the 2.7 fix to see if that may apply for this issue in 2.8 as well.  If I stumble upon, I will post here for any others with the same issue.

In reply to Rachel Epler

Re: Error fetching OAuth2 access token

by Ken Task -
Picture of Particularly helpful Moodlers

Well, I'll be DANG!  It's broke ... again ... in 28 and 29 sandbox sites that have recently been git updated.

The 2.7 sandbox is working with the forum offered fix.   The other sandboxes - 2.8, 2.9, worked just 2-3 days ago now don't.   So have to wonder ... update whack or Google whack?

Dig ... Dig ... Dig ...  Error screens from Google not always the same.   And I'll be darn if the console area hasn't also changed.    Beginning to think this is somewhat a 'perfect storm' situation.

If I find something, I'll come back!

'spirit of sharing', Ken

In reply to Ken Task

Re: Error fetching OAuth2 access token

by Rachel Epler -

Bummer!  Although there is a little peace of mind that it's not something in my specific configuration. smile

I will keep digging as well and post if I find something.

Thanks, again!

In reply to Rachel Epler

Re: Error fetching OAuth2 access token

by Ken Task -
Picture of Particularly helpful Moodlers

Well, got 2.8 working again with a 'work-around' - which might really not be needed.  Beginning to think issue was a 'hickup' on Google's end ... but no real proof of that! :\

My instance probably not the same as yours (maybe) as I use a plugin for Google Oauth authentication:

https://moodle.org/plugins/view/auth_googleoauth2

Plus, had Google Drive turned on and configured.

So the credentials client ID was the same for both, but the Client Secret different as well as the Authorized Redirect URI for both.

Deleted the instances in Google and rebuilt them - recording the ClientID and secret and making sure the 'callback'/redirect URL was correct.

Turned on debugging.   Got:

Debug info:
Error code: invalidstateparam
$a contents:
Stack trace:
line 76 of /auth/googleoauth2/lib.php: moodle_exception thrown
line 19 of /auth/googleoauth2/google_redirect.php: call to googleoauth2_provider_redirect()

Naturally, the link to 'more info' had nothing. :\  (not being critical there, cause documenting every possible error generated by addons/plugs and working with Google, is pretty near mission impossible).  So ... started inspecting line 76 of lib.php

Commented out the section of code (from { to the enclosing }) that had this as the comment before it.

    // Ensure that this is no request forgery going on.
    // And that the user sending us this connect request is the user that was supposed to.

And then tried it again.   Worked.

Even Google Drive worked.

So call it a 'work-around' ... that probably shouldn't stay.

Am gonna wait a day or two, go back to that file and re-instate the lines to check.

Soooo ... conclusion ... I don't know for sure! :\

'spirit of sharing', Ken

In reply to Ken Task

Re: Error fetching OAuth2 access token

by Jason Touw -

Hi Ken,

It has been several months since your post on this forum.  I am wondering where we are at with this?  We are running Moodle v3.0.  For the first month, the Google Drive plugin worked fine.  Then about a week ago, the same Error listed in earlier posts:

Exception - Error fetching OAuth2 access token, message: ''

More information about this error

Debug info: 
Error code: generalexceptionmessage
Stack trace:
  • line 125 of \lib\google\src\Google\Auth\OAuth2.php: Google_Auth_Exception thrown
  • line 128 of \lib\google\src\Google\Client.php: call to Google_Auth_OAuth2->authenticate()
  • line 120 of \repository\googledocs\lib.php: call to Google_Client->authenticate()
  • line 62 of \repository\repository_callback.php: call to repository_googledocs->callback()
Output buffer: <br /> <b>Notice</b>: Undefined variable: errorText in <b>C:\Moodle30\server\moodle\lib\google\src\Google\Auth\OAuth2.php</b> on line <b>129</b><br />


Any thoughts on a workaround this?  Tried creating a new API and Secret Key on Google Developers and still no luck.


Thanks!

In reply to Jason Touw

Re: Error fetching OAuth2 access token

by Ken Task -
Picture of Particularly helpful Moodlers

Google has changed the console interface ... and, at least with the many such credentials setups I had (all were 2.x versions of Moodle) in my account, ONLY 4 were showing.   Yet, on many sites where I had Google Oauth2 for authenticating vs Google (an addon/plugin for auth - NOT the Google Drive Repo) have been working even if they weren't listed in Google Console!  Dunno what's up with that ... but ...

Just setup a Google Drive repo on a 3.0.2 (Build: 20160111) successfully (already had the site setup for authenticating vs Google).   The steps you've done so far sounds like you've done them correctly.   One thing that I had to remember to do ... when accessing Google Console in a browser window to acquire the key/secret etc.   had to make sure, after getting the key and secret into Moodle, to close that Google popup window that showed me the info *** AND logout of Google**.   If I stayed logged on to Google and came back to the Moodle to test, I was already logged onto Google and Moodle does a check - which throws an error - if it finds I'm already logged on.

The other thing I had forgotten, during first use ... one is prompted with another box for granting permissions for the Google API to be allowed to access *users* Google Docs ... remember seeing these (at any time?







and the following screen:

Comment: when ever an app uses a 3rd party API, chances are, things will break at some point ... not Moodles fault ... not Google's fault.   It's just change ... but does require re-config and can be VERY frustrating.   The timing of 3.x release and the change to Google API/Console can't be coordinated ... Google programmers don't 'inform' Moodle programmers and vice versa (why would Google programmers of the Oauth2 API etc. even care about Moodle given the existence of Google Classroom now? - food for thought, not answering!).

Now when the error shows, it should show in that popup box for authenticating to Google.    There is a triangle for more info in at popup authentication box.   Get a look at that.

So that's where I am with this ... 'we' might not apply here as I don't run Windows (could be a factor considering M$ would prefer you use their 'cloud offerings' now.   And, please, NONE tell me that M$ wouldn't do that ... it was only a year ago that the Netscape Communications suit was finally settled out of course [non-disclosure, of course!] but M$ was found to be at fault.   A Leopard doesn't change spots, as far as I know. :|

All I can tell you ... keep at it.

'spirit of sharing', Ken

In reply to Ken Task

Re: Error fetching OAuth2 access token

by Jason Touw -

Hi Ken,

Yes, I do get the screen that you took a snapshot of....Yes, I did try logging out of Moodle and Google and closing Chrome and then reopening a new browser window.  No luck.


So there it is...looks like maybe a go...!


And then...



So here is the interesting part.  Those images you just saw above....well I tried to access them on THIS forum, Moodle.org, using the Google Drive plugin....




Google Drive doesn't work here on this website either!  Different error but no sync!  Is it working for you on Moodle.org?  Any thoughts?

In reply to Jason Touw

Re: Error fetching OAuth2 access token

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Jason,

After reading your post I checked the Google Drive repository on https://qa.moodle.net/ and on moodle.org, and obtained the same error as you did (redirect_uri_mismatch).

I was able to fix the https://qa.moodle.net/ problem by adding the correct URI in the Google Developers Console. I didn't understand why we were getting the error for moodle.org, as the correct URI was entered in the Google Developers Console. thoughtful In the end I decided to set up a new Google Developers Console project and obtain a new client ID and secret, and now the Google Drive repository works on moodle.org. wide eyes

Probably none of my findings are of help to you, sorry. I can sympathise with your frustration though.

Average of ratings: Useful (1)
In reply to Ken Task

Re: Error fetching OAuth2 access token

by Jason Touw -

Do you recommend downloading and using a plug in for authentication on moodle 3.0?

Also, you wrote, "Now when the error shows, it should show in that popup box for authenticating to Google.    There is a triangle for more info in at popup authentication box.   Get a look at that."

Can you give me a little more info?  Where is the triangle you speak of?

In reply to Rachel Epler

Re: Error fetching OAuth2 access token

by Ken Task -
Picture of Particularly helpful Moodlers

@Rachel

What version of Moodle are you running? and do you have a Google OAuth 2 *authentication* addon as well?

In a freshly git pulled 2.9.2 (Build: 20150914)' with no addons, there is no

/lib/google/Google directory.

There is a /lib/google but it does not contain another directory called 'Google'.

There is a /lib/google/src/Google directory, however.

And it appears you are having issues with Google Docs repository.

The call back/redirect url's are different for each Google instance and those must be taken from the setup of the API @ Google.   They might have the same client ID, but the secret should be different for each API configured.   Google Docs and Picassa, for example.

'spirit of sharing', Ken