by Dillon Esterhuizen.
An update to this.
I tried using it with Google Oauth2 service and it works fine.
For some reason, with the custom service, the oauth2callback.php file is not getting the sesskey parameters from the URL, although it is in the URL. I'm not sure why this is happening.
I'm also not sure whether the order of the params in the URL makes any difference? For example, I see that Google redirects to the following:
/admin/oauth2callback.php?state=/auth/oauth2/login.php?wantsurl(myurl)&sesskey=(mysesskey)&code=(mycode)
But the custom service redirects to:
/admin/oauth2callback.php?code=(mycode)&state=/auth/oauth2/login.php?wantsurl=(myurl)&sesskey=(mysesskey).
Also, not sure if it's relevent but the Google redirect has the & and ? and = encoded into something like %26, %3D, etc. whereas my custom service redirect has the actual & or ? or =.