OAuth with Gmail working!

After 2 days of trial and error I finally got gmail working with OAuth without resorting to App password.
I’m running SCRM 7.14.7

  1. Setup your google stuff in console.google.com first. There are plenty of Tutorials to do this. This will give you Your Client Id & Client Secret to enter in the next next step on SCRM.

  2. Setup an External OAuth Provider. (Admin>Email>External OAuth Providers)

Authorize Url Options is ‘Scope’ & ‘https://mail.google.com/ openid email profile’.
The 3rd Extra Params is ‘urlResourceOwnerDetails’ & ‘https://openidconnect.googleapis.com/v1/userinfo’.

  1. Make the following code changes;

in Modules/ExternalOAuthConnection/provider/ExternalOAuthProviderConnector.php
Comment out line 122
add lines as follows;

        //$authUrl = $provider->getAuthorizationUrl($this->getAuthorizeURLOptions($config));
        $authUrl = $provider->getAuthorizationUrl([
            'scope'        => $scopes,
            'access_type'  => 'offline',
            'prompt'       => 'consent',
        ]);

in vendor/league/oauth2-client/src/Provider/AbstractProvider.php

Comment out line 423;
//'approval_prompt' => 'auto'

(this setting is deprecated)

  1. Setup an External OAuth Connector. (Admin>Email>External OAuth Connectors)
    Give it a name and choose the Provider created earlier.
    Click Authorise and complete the Google Account login.
    When you are returned an Access Token and a Refresh Token should be populated.
    If it only says ‘array’ in the Refresh Token, you may not have made the code changes described above correctly.
    If all went well, inbound and outbound emails can now be setup.

Good luck.

8 Likes

We are using gmail account. Do we need to set up OAuth?

No, you could use an App password but that is less secure.
That’s the reason I changed to OAuth. It’s easy enough if you follow my instructions above.

Cheers
Terry

1 Like

Understood! Thank you so much for the quick response. :smile:

This link is not working for me.

Try console.cloud.google.com
Or search console google
Cheers
Terry

1 Like

Thank you very much. The change to the ExternalOAuthProviderConnector.php line is what was most difficult for me to figure out. It almost took me a whole day without your guide.

1 Like

Wanted to thank you very much for all this information.
I should add that I did not need to modify any code in the 2 files mentioned on SuiteCRM 8.9.2.

1 Like