• Resolved dblooper

    (@dblooper)


    Hello all, I am trying to add custom scopes to the google registration process.

    I have everything set up properly in google console. I know this because when using the plugin “login with google” I am able to use the following code to create a custom plugin that piggybacks off the “login with google” plugin and it requests additional scope permissions from users.

    <?php
    /**
     * Plugin Name: Custom Google Login
     * Description: A custom plugin to extend the "Login with Google" plugin by adding additional scopes.
     * Version: 1.0
     * Author: DB_Looper
     */
    
    if (!defined('ABSPATH')) {
      exit;
    }
    
    function custom_google_login_add_scopes($scopes) {
      $additional_scopes = array(
        'https://www.googleapis.com/auth/drive.file',
        'https://www.googleapis.com/auth/spreadsheets',
      );
    
      return array_merge($scopes, $additional_scopes);
    }
    add_filter('nextend_social_login_google_scopes', 'custom_google_login_add_scopes');

    However, no matter what I try, I cannot figure out how to get anything similar working with Nextend.

    I’m using Nextend because I couldn’t get the access token from the login with google plugin. But now I can get the scopes requests to work.

    Anyone have any advice on how to fix this delima?

    • This topic was modified 1 year, 10 months ago by dblooper.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Laszlo

    (@laszloszalvak)

    Hi @dblooper !

    The problem is, that you are trying to hook your function to a filter that does not exist:

    • nextend_social_login_google_scopes

    The filter where you could extend / override the scopes of our providers is named more like this:

    • nsl_{{providerId}}_scopes

    Here is a simple example for Google:

    add_filter('nsl_google_scopes', function ($scopes) {
        /**
         * Push extra scopes here into the $scopes array.
         */
        
        return $scopes;
    });

    Best regards,
    Laszlo.

    Thread Starter dblooper

    (@dblooper)

    Thanks Laszlo! Got it working now. Here’s the working custom plugin incase anyone searches the threads looking for the same thing.

    <?php
    /**
     * Plugin Name: Custom Nextend Google Login
     * Description: A custom plugin to extend the Nextend Social Login Google registration process with additional Google Drive and Sheets permissions.
     * Version: 1.2.0
     * Author: DB_Looper
     * License: GPL-2.0+
     * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
     */
    
    if (!defined('ABSPATH')) {
        exit; // Exit if accessed directly
    }
    
    add_action('plugins_loaded', 'cgl_extend_nextend_google_registration', 20);
    
    function cgl_extend_nextend_google_registration() {
        if (class_exists('NextendSocialLoginPRO')) {
            add_filter('nsl_google_scopes', 'cgl_add_additional_scopes');
        } else {
            add_action('admin_notices', 'cgl_nextend_social_login_required_notice');
        }
    }
    
    function cgl_add_additional_scopes($scopes) {
        $additional_scopes = array(
            'https://www.googleapis.com/auth/drive.file',
            'https://www.googleapis.com/auth/spreadsheets',
        );
    
        return array_merge($scopes, $additional_scopes);
    }
    
    function cgl_nextend_social_login_required_notice() {
        $class = 'notice notice-error';
        $message = __('The "Custom Google Login" plugin requires the Nextend Social Login Pro Addon to be installed and activated.', 'custom-google-login');
    
        printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
    }
    
    • This reply was modified 1 year, 10 months ago by dblooper.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Custom Scope Permissions’ is closed to new replies.