Title: OAuth2 coding advice?
Last modified: August 22, 2016

---

# OAuth2 coding advice?

 *  Resolved [Jason Hendriks](https://wordpress.org/support/users/jasonhendriks/)
 * (@jasonhendriks)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/oauth2-coding-advice/)
 * Hi Dan, I’m the author of an [OAuth2 SMTP plugin](https://wordpress.org/plugins/postman-smtp/),
   and I was hoping you wouldn’t mind me picking your brain about something, as 
   you’ve been in the OAuth2 space much longer than I have.
    1. Do you have a best-practice solution for preventing collisions with other plugins
       using the Google API? [I’ve run into such a situation](https://wordpress.org/support/topic/fatal-error-on-registration-form?replies=4#post-6655955)
    2. Is there special handling for Redirect URLs in a WPMU (multisite) environment?
 * I appreciate any advice you’d be willing to share `:>`
 * Thanks!
    Jason (jason-at-hendriks-dot-ca)
 * Update: [Saw this](https://wordpress.org/support/topic/error-on-login-page-3?replies=6).
   Oh wow is it really that simple??
 * [https://wordpress.org/plugins/google-apps-login/](https://wordpress.org/plugins/google-apps-login/)

Viewing 1 replies (of 1 total)

 *  [danlester](https://wordpress.org/support/users/danlester/)
 * (@danlester)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/oauth2-coding-advice/#post-5868405)
 * Jason,
 * Great to hear from you – thank you for reaching out!
 * The thread you found (in which I’m hailed a hero!) describes the basic principle–
   that we need to rename any top-level ‘global’ variables/classes so they don’t
   conflict with other versions of the Google client library.
 * WordPress in general seems to encourage constructions like: if (!class_exists(…)){/*
   define class */, but I think that is incredibly dangerous – you may pull in an
   unexpected version of the class giving unpredictable results. A “can’t redefine
   class” error would be preferable.
 * The worst case is that one plugin chooses not to redefine the Google classes,
   so things seem to work, but then it turns out that whichever other plugin loaded
   the library was using the wrong version.
 * So I renamed every top level class in Google’s client library from Google_* to
   GoogleGAL_* (GAL = Google Apps Login, hopefully unique). Obviously, you need 
   to choose something different…
 * That worked well, but when I updated to a more recent release of Google’s client
   library, I did not realize they had introduced a new top level function called
   google_api_php_client_autoload. So in the thread that you found, that’s where
   I also had to rename that (and rejig its code a bit to match my renaming of Google_*
   to GoogleGAL_*).
 * Regarding redirect URLs, I always use /wp-login.php so things are probably different
   for you. On multisite, I have an option (default) to always use the root site’s/
   wp-login.php, or (harder for the user to configure) each site’s own /subsite/
   wp-login.php URL. The second option is slightly tidier for the user experience,
   but the admin has to register every possible subsite in the Google Cloud Console
   project.
 * I hope this helps. I’ll send you an email too so we can keep in touch.
 * Thanks,
 * Dan

Viewing 1 replies (of 1 total)

The topic ‘OAuth2 coding advice?’ is closed to new replies.

 * ![](https://ps.w.org/google-apps-login/assets/icon-256x256.png?rev=2834114)
 * [Login for Google Apps](https://wordpress.org/plugins/google-apps-login/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-apps-login/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-apps-login/)
 * [Active Topics](https://wordpress.org/support/plugin/google-apps-login/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-apps-login/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-apps-login/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [danlester](https://wordpress.org/support/users/danlester/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/oauth2-coding-advice/#post-5868405)
 * Status: resolved