Posted by Igor Benic

Web Developer who mainly uses WordPress for projects. Working on various project through Codeable & Toptal. Author of several ebooks at https://leanpub.com/u/igorbenic.

20 Comments

  1. This has been extremely helpful in getting my headless WP backend up and running using the facebook login SDK!! Its very rare to find help on headless wp builds/setups & process, site bookmarked! Great job of explaining and code sharing. Thank you so much for all the help!

    Reply

    1. Hey Igor and Spencer,

      I was looking also for Facebook login implementation.

      Would you like to share yours?

      Reply

  2. How can I setup autoload help me please

    Reply

    1. Once you install the packages using composer, the autoload.php provided by composer will be enough to autoload classes.

      If you have not yet been introduced to composer, you can check their site: https://getcomposer.org/

      If you would like create your own custom autoloaders, you can then here is an article from Tom McFarlin about creating autoloaders for WordPress projects: https://tommcfarlin.com/simple-autoloader-for-wordpress/

      Reply

  3. protected $googleClient = ‘YOUR_GOOGLE_CLIENT_ID’;

    should i replace ‘YOUR_GOOGLE_CLIENT_ID’ with id i get from google console ?

    Reply

    1. Yes, that’s the long google client id. You can see for example in their own code example: https://developers.google.com/identity/sign-in/web/build-button#building_a_button_with_a_custom_graphic how they use the client ID.

      But in this code you use the whole part (.apps.googleusercontent.com included).

      Reply

      1. thank you very much , implemented with React-native / wp backend
        and it work like a charm

        Reply

  4. Wisnu Eka Saputra February 5, 2020 at 7:56 am

    Hey. Thanks for your tutorial dude. It works on localhost but when on live site it returns 404 route not found. Can you help me?

    Reply

    1. Hi Wisnu, if I understood correctly, the route is 404? Not page 404?

      In case the route is 404 (not found) it might be that the URL to the route is incorrect or some other plugin is maybe blocking that?

      Or try updating permalinks (Settings > Permalinks > Save Changes). It should not be related to permalinks but you never know 🙂

      Reply

      1. Wisnu Eka Saputra February 11, 2020 at 8:18 am

        Nice man, thanks. but i get invalid-token code when i try to post on post man. i get the id_token from developers.google.com/oauthplayground. i check on jwt.io it contain the userdata from google. but still return invalid-token. how can i resolve that? thanks

        Reply

  5. In the class-login-2.php file, I do not see the Client.php in the mentioned path ‘/vendor/google/apiclient/src/Google/Client.php’.
    Also this path ‘\Firebase\JWT\JWT;’

    I have downloaded the google client api from the below links, I checked in both of the zip files.
    https://github.com/googleapis/google-api-php-client/releases
    google-api-php-client-2.5.0.zip
    google-api-php-client-2.5.0_PHP54.zip

    can anyone tell how I have to setup Google Client API without composer.

    Reply

  6. Hi there I’m stuck with this error `Notice: Undefined offset: 0 in /Applications/XAMPP/xamppfiles/htdocs/carstime/wp-includes/rest-api/class-wp-rest-server.php on line 179` I can’t get rid of or understand what I did wrong

    Reply

    1. Chintankumar Patel December 22, 2020 at 10:53 pm

      Hesham what was the reason for this error?. I am getting the same error. I need to fix this.

      Reply

    2. Chintankumar Patel December 22, 2020 at 10:56 pm

      How did you solve this?. I am having the same error.

      Reply

  7. I got fixed the error but now it returns always false whatever within my Android Google id Token that I get, I tried to see if the problem from my Android phone by requesting into https://www.googleapis.com/oauth2/v1/tokeninfo?id_token={idToken} and returns valid but with my custom endpoint always return invalid token or payload: false

    Reply

    1. Hi Hesham, what do you mean by Android Google ID token? Isn’t that a different thing?

      Reply

  8. Awesome post! Exactly what I needed for a headless wordpress setup using the JWT Autho for WP REST API plugin and a google login.

    Reply

  9. Is this going to work with the migration that is taking place? https://developers.google.com/identity/gsi/web/guides/migration

    Reply

    1. Don’t know really. Haven’t tested it with the new version.

      I guess with a few changes it should work fine. Seems like it might be easier now.

      Reply

  10. Wow, what a tuto ! That’s exactly what I was searching for.
    No one explains how to do that. It was realy a good basis to implement google login in worpress in combo with vue.js.
    Thank you much and keep up good work.

    Reply

Leave a reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.