Update Sitecore Social Connector to Google Sign in

Director, Sitecore Practice
  • Twitter
  • LinkedIn

Update Sitecore Social Connector to Google Sign-in

As many may know, Google+ is going away. Developers are to migrate from Google+ Sign-in to Google Sign-in. Per Sitecore support, Sitecore social connector is no longer supported for versions of Sitecore under 9.0. This post will discuss what needs to be done to update the Sitecore social connect to work with Google Sign-in.

Per Google, the requested scopes need to be changed. Exploring the social connector DLL s via dotPeek, we found that relevant scope was hardcoded in the paths factory:

Sitecore.Social.GooglePlus.Connector.Paths.GooglePathsFactory

Exploring further, this is referenced by the class

Sitecore.Social.GooglePlus.Networks.Providers.GooglePlusProvider

For simplicity, rather than changing the factory, we opt to change the GooglePlusProvider only. Below are the relevant areas of changes. Please note that you will have to include the rest of the GooglePlusProvider class.

namespace YourNameSpace.Providers
{
    public class GooglePlusProvider : NetworkProvider, IAuth, IGetAccountInfo, IAccessTokenSecretRenewal
    {
        //these can be moved to a config file
        private readonly string _loginScope = "profile";
        private readonly string _emailScope = "email";

        public void AuthGetCode(AuthArgs args)
        {
            this._provider.ClientIdentifier = args.Application.ApplicationKey;
            this._provider.ClientSecret = args.Application.ApplicationSecret;
            var authorizationState = new AuthorizationState(new List()
                {
                    _loginScope,
                    _emailScope
                });
             ...
        }

        public void AuthGetAccessToken(AuthArgs args)
        {
            HttpRequest request = HttpContext.Current.Request;
            if (!string.IsNullOrEmpty(request.QueryString?.Get("error"))) return;

            var code = request.QueryString.Get("code");
            if (string.IsNullOrEmpty(code)) return;

            this._provider.ClientIdentifier = args.Application.ApplicationKey;
            this._provider.ClientSecret = args.Application.ApplicationSecret;

            AuthorizationState authorizationState = new AuthorizationState(new List()
                {
                    _loginScope,
                    _emailScope
                });
            ...
        }

        private IAuthorizationState GetAuthState(string accessToken)
        {
            return new AuthorizationState(new List()
                {
                    _loginScope,
                    _emailScope
                })
                {
                    AccessToken = accessToken
                };
        }

The app_config/include/ file


  
    
      
        
          
            
          
        
      
    
  

View more blogs and tutorials about Sitecore

Learn about our Sitecore work

Related Blogs

Latest Blogs