• Resolved Alfio Piccione

    (@picaland)


    I’m trying to use the plugin to obtain user authentication through the use of the REST API, made available to the pluign.
    endpoint: wp-json / nextend-social-login / v1
    from what I understand from the code it would be enough to pass the provider es “google” and google access_token

    but this returns “Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.”

    although I set the token in “The authorization data”,
    what would be the exact work flow to get a social login via REST API?

    thanks!

Viewing 15 replies - 16 through 30 (of 47 total)
  • Thread Starter Alfio Piccione

    (@picaland)

    Hi @sawasblog and @jwasily

    I made a small plugin that through the use of NSL and JWT plugins, implements a social login via REST Api.
    Warning: Correct operation assumes that the two plugins are configured correctly as indicated in the respective documentation.

    The plugin merely implements the flow to be able to log external apps via social login (facebook and google) or through native login (user and password).

    By properly activating and configuring JWT, every WordPress REST endpoit is protected. Any unprotected endpints can be run using the “sl_extended_no_auth_request” filter.

    you can download the plugin for free using the discount code: sljwtfree

    here is the link to the plugin
    you will also find a PDF in English explaining how to use it.

    I hope it helps.

    I am sorry to bother you, but when the plugin is activated i get theis error every ime i try to login with

    https://mywebsite.com/wp-json/jwt-auth/v1/token?username=test&password=test

    [07-Feb-2020 19:37:16 UTC] PHP Fatal error: Uncaught Error: Class ‘RestApi’ not found in /home/mywebsite/wp-content/plugins/extended_nsl_jwt_social_login_rest_api/index.php:946
    Stack trace:
    #0 /home/ask.jaratii.com/wp-includes/class-wp-hook.php(288): {closure}(Object(WP_REST_Server))
    #1 /home/16 /wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(NULL, Array)
    #2 /home/16 /wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #3 /home/16 /wp-includes/rest-api.php(471): do_action(‘rest_api_init’, Object(WP_REST_Server))
    #4 /home/16 /wp-includes/rest-api.php(298): rest_get_server()
    #5 /home/16 /wp-includes/class-wp-hook.php(288): rest_api_loaded(Object(WP))
    #6 /home/16 /wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(”, Array)
    #7 /home/16 /wp-includes/plugin.php(544): WP_Hook->do_action(Array)
    #8 /home/16 /wp-includes/class-wp.php(387): do_action in /home/16 /wp-content/plugins/extended_nsl_jwt_social_login_rest_api/index.php on line 946

    what could be the problem ?

    Plugin Support Laszlo

    (@laszloszalvak)

    Hi @sawasblog

    Please note that, we can not provide support for custom coding, but these:
    PHP Fatal error: Uncaught Error: Class ‘x’ not found
    errors usually occur when the class you are trying to instantiate is not included, yet. In your case the RestApi class.

    You could try including it via “require_once”
    https://www.php.net/manual/en/function.require-once.php
    in your index.php and that will most likely fix the problem.

    Best regards,
    Laszlo.

    @picaland

    I am sorry to bother you, but when the plugin is activated i get theis error every ime i try to login with

    https://mywebsite.com/wp-json/jwt-auth/v1/token?username=test&password=test

    [07-Feb-2020 19:37:16 UTC] PHP Fatal error: Uncaught Error: Class ‘RestApi’ not found in /home/mywebsite/wp-content/plugins/extended_nsl_jwt_social_login_rest_api/index.php:946
    Stack trace:
    #0 /home/ask.jaratii.com/wp-includes/class-wp-hook.php(288): {closure}(Object(WP_REST_Server))
    #1 /home/16 /wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(NULL, Array)
    #2 /home/16 /wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #3 /home/16 /wp-includes/rest-api.php(471): do_action(‘rest_api_init’, Object(WP_REST_Server))
    #4 /home/16 /wp-includes/rest-api.php(298): rest_get_server()
    #5 /home/16 /wp-includes/class-wp-hook.php(288): rest_api_loaded(Object(WP))
    #6 /home/16 /wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(”, Array)
    #7 /home/16 /wp-includes/plugin.php(544): WP_Hook->do_action(Array)
    #8 /home/16 /wp-includes/class-wp.php(387): do_action in /home/16 /wp-content/plugins/extended_nsl_jwt_social_login_rest_api/index.php on line 946

    what could be the problem ?

    Thread Starter Alfio Piccione

    (@picaland)

    @sawasblog

    Sorry, little mistake.
    Download the plugin again.
    Remember that the login request is a POST request

    @picaland

    Thank you for your time ,

    So what i did is i got facebook token (my_fb_token) then using POSTMAN i sent

    {“access_token”:”my_fb_token”,”token_type”:”bearer”,”expires_in”:5183946,”email”:”[email protected]”}

    But he response of the social login request is not identical to that of the native login , i got “Authentication successful” in response but what i really need is the token generated by JWT so that i can perform any protected requests

    The response that i get :

    <!doctype html>
    <html lang=en>
    <head>
    <meta charset=utf-8>
    <title>Authentication successful</title>
    <script type=”text/javascript”>
    try {
    if (window.opener !== null && window.opener !== window) {
    var sameOrigin = true;
    try {
    var currentOrigin = window.location.protocol + ‘ //’ + window.location.hostname;
    if (window.opener.location.href.substring(0, currentOrigin.length) !== currentOrigin) {
    sameOrigin = false;
    }
    } catch (e) {
    // Blocked cross origin
    sameOrigin = false;
    }
    if (sameOrigin) {
    window.opener.location = “https://mydomaine.com&#8221;;
    window.close();
    }
    }
    }
    catch (e) {}
    window.location = “https://mydomaine.com&#8221;;
    </script>
    <meta http-equiv=”refresh” content=”0;https://mydomaine.com”&gt;
    </head>
    <body>
    </body>
    </html>

    • This reply was modified 4 years, 9 months ago by eljara.
    Thread Starter Alfio Piccione

    (@picaland)

    @sawasblog

    The answer he gets is an HTML page while you should have a json.
    Could you show me how you send the request?

    @picaland

    After i get the fb tokin,
    I send a POST to : mywebsite/wp-json/api/v1/social-login/facebook/

    With these parameters:

    access_token, email, token_type, expires_in

    Where access_token us the token thqt i get from facebook login

    Thread Starter Alfio Piccione

    (@picaland)

    @sawasblog

    Very strange, I get the json answer, as you can see from the image.

    https://pasteboard.co/ITHnv9z.png

    Is the NSL plugin properly configured for Facebook?

    @picaland

    You have the latest version of both plugins ?

    @picaland
    “Is the NSL plugin properly configured for Facebook?”

    Yes it is , when i login from the website everything works as expected

    Thread Starter Alfio Piccione

    (@picaland)

    JWT Authentication for WP-API – 1.2.6
    Nextend Social Login – 3.0.20

    I can check the whole flow again to see if I have left something out … otherwise it is to be verified …

    @picaland

    This is the request that i send and the response that i get, i tried reinstalling all the plugins

    request
    https://pasteboard.co/ITItYJf.png

    response
    https://pasteboard.co/ITIufGG.png

    Thread Starter Alfio Piccione

    (@picaland)

    @sawasblog

    I revised the plugin, I fixed some things due to the fact that in my project the classes were in the theme, while in this case we are in a plugin.
    I did tests in a new installation, it’s all ok now
    Download again.

    Thank you very much , it’s working now i just cheeked

    Thank you for your time , i wish you the best

Viewing 15 replies - 16 through 30 (of 47 total)
  • The topic ‘REST api social login work flow’ is closed to new replies.