0

I am currently developing an OAuth2 plugin where I need to implement a callback URL for handling authentication logic. Currently, I have the logic hooked into the init function, checking if the URL has appropriate arguments like ?auth=github, and handling the authentication logic there. Here's a snippet of the code:

// ... (Constructor function)

public function __construct() {
    if(wp_doing_ajax()){
        return;
    }

    if ( wp_doing_cron() ) {
        return;
    }

    if ( headers_sent() ) {
        return;
    }

    // If doing then, set auth stage and provider name
    if(!$this->doing_social_auth()){
        return;
    }

    if(!$this->is_provider_supported($this->provider)){
        return;
    }

    if(!$this->initialize_settings()){
        return;
    }

    if(!$this->is_provider_enabled($this->provider)){
        return;
    }

    $this->handle_social_login($this->provider);
}

However, I have noticed a slight delay when redirecting to the callback URL, and there's additional checking for cron and Ajax operations. Also Callback page check logic executes on every page load, so it could lead to higher server load.

I am considering separating the logic into a dedicated page, possibly creating a plugin-specific standalone page like callback.php. After researching on Stack Overflow, I learned about options like template_include and rewrite_rule. I am confused about the best approach and the advantages of using one over the other. Could someone provide insights into the best practices for implementing OAuth2 callback logic in a dedicated page vs. within the init hook in a WordPress plugin?

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.