• Resolved stevemoretz

    (@stevemoretz)


    Perfect plugin, not a perfect way to register or login programmatically.

    It is mentioned in the docs that register and login through api is not supported, well it makes sense we need to connect it to our authentication systems (whatever we use), why do we need a ready api for that?

    But here at number (3) https://nextendweb.com/nextend-social-login-docs/nextend-social-login-rest-api/

    You are suggesting this gist : https://gist.github.com/nextend/012ca54957e27dbea952fc42195fb0d1
    to make our own register and login with it.

    It is good but not good enough, you already take care of a lot such a grabbing the brith-day from google getting the avatar and so on.

    Why would we need to re-implement all those once again in our register logic?

    Long story short, you need to provide a function that we can call, pass in the access_token and provider and it should handle register if the user is not already register and return its ID, if the user has registered just return its ID.

    This makes a lot of sense why do we need to do everything you’ve done again? But not having a rest api for it as you decided makes sense we just need a
    better function for doing it ourselves.

    ——

    Okay, let’s get to it, I have read your code and in a way did it. (it’s a workaround or a hack). the main issue with your code is in just blindly redirects and exits here and there, if you put an option for that (a couple of if statements here and there) and we are done.

    $providerID = $params["provider_id"];
    $accessToken = $params["access_token_data"];
    
    $data = [
        "access_token_data" => $accessToken,
    ];
    
    // it's an api we don't need auth cookies, disable them.
    add_filter("send_auth_cookies", "__return_false");
    // nextend outputs some html for redirection don't let it output it.
    ob_start();
    if (NextendSocialLogin::isProviderEnabled($providerID)) {
        $provider = NextendSocialLogin::$enabledProviders[$providerID];
        try {
            /**
             * suggested by nextend from https://gist.github.com/nextend/012ca54957e27dbea952fc42195fb0d1
             *
             * This basically gets userdata from access_token and saves it on the provider.
             */
            $socialID = $provider->findSocialIDByAccessToken(
                $accessToken
            );
    
            // found by me which is internally used for register and login.
            $socialUser = new NextendSocialUser($provider, $data);
    
            // logout if it is already logged in, otherwise NextendSocialUser won't respond.
            if (get_current_user_id() > 0) {
                wp_logout();
            }
    
            // after liveConnectGetUserProfile on $socialUser(NextendSocialUser) has runs it will redirect and exit so let's catch it before it exits
            register_shutdown_function(function () use (
                $socialUser,
                $socialID
            ) {
                //region get rid of the html nextend outputs for redirection.
                ob_get_clean();
                ob_flush();
                //endregion
                $user_id = $socialUser->getProvider()->getUserIDByProviderIdentifier($socialID);
                // or get_current_user_id();
                var_dump($user_id);
                // we are done here! well after a lot of twists and turns, it works but why does it need to be like this? it doesn't.
            });
            /**
             * does the login or register on access token then you can get user id after this, via
             * 1. get_current_user_id()
             * or
             * 2. $user_id = $socialUser->getProvider()->getUserIDByProviderIdentifier($socialID);
             *
             */
            $socialUser->liveConnectGetUserProfile();
        } catch (Exception $e) {
            // TODO do something about exceptions.
        }
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Laszlo

    (@laszloszalvak)

    Hi @stevemoretz

    I am sorry, but we don’t have plan to allow the registration with Nextend Social Login by passing access tokens to our endpoints, as we try to avoid methods that could create possible security vulnerabilities in our plugin.
    Nextend Social Login works that way, that it registers the new accounts on your site only if the data comes from our own authentication flow.

    Also you shouldn’t use our liveConnectGetUserProfile() function at all, as that does much more than simply registering the new accounts.
    It might worked for the use-case you tested, but in other cases it can cause unexpected results and we can not provide support for such problems or problems caused by custom codes.
    As we mentioned in the REST API documentation:

    the registration and the login parts needs to be implemented by you.

    Either ways I started working on a simplified registration skeleton code that we might put in the documentation, but there are some topics that I will need to discuss with our Senior Developer.

    I will let you know if we have any news on this matter. Thank you for your patience!

    Best regards,
    Laszlo.

    Thread Starter stevemoretz

    (@stevemoretz)

    Thank you so much for this great information! I would love to see your skeleton code here, once you decided it’s ready even if it doesn’t end up in the docs (which hopefully it does).

    BTW I could not find my rating (it was 4 stars) to change to 5, I added another rating with 5 stars if there is a problem please send me the link of my old review to make that 5 as well.

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @stevemoretz

    As for the skeleton code:
    I will inform you once it is ready.

    As for the previous review:
    As I see that review was deleted as it violated the review policy. This was the message that the forum moderation staff left in that topic when it was deleted:

    "if it gets resolved this immediately turns to 5."
    
    @stevemoretz Don't do that. That's using a review to extort a result.
    I have removed your review. Please do not use the review section for support.
    If you need support then please raise a support topic.

    So don’t worry about that review and thank you for the new 5* review!

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @stevemoretz

    Our skeleton code is ready. But to make it as simple as possible, we also had to implement some new functions.
    So to be able to work with this skeleton code you will need to install our latest build, too.

    Could you get in touch we us over the ticket system, please?

    there I will send you:

    • the installers of the latest build
    • and our skeleton code

    Then if you find it convenient enough, then we will also put it into one of our Developer documentations.

    Best regards,
    Laszlo.

    Hi @laszloszalvak,

    I would also be interested in being able to review the Skeleton Code mentioned above. I have submitted a ticket to the URL provided to the OP.

    Thanks is advance,
    Andrew

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @aefurrer2010

    I have just replied to your support ticket and sent you the skeleton code in email.
    Could you check your inbox please?

    If you have any feedbacks on the skeleton code, please reply to the email that I sent you over the ticket system.

    Best regards,
    Laszlo.

    Thank you so much @laszloszalvak this code was extremely helpful, and was able to use portions to aid in my implementation of both Google and Facebook custom routines!

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @aefurrer2010

    Thank you for your feedback!

    I am glad you found the skeleton code useful.
    In the future, we will add it to our Developer documentation, too.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Problem with your api registration logic’ is closed to new replies.