AppDividend
Latest Code Tutorials
54 Comments
  1. Gabriel Marquez says

    Nice post, It works fully, I followed step by step. However, it just works for the facebook account you set up on the dashboard of facebook developer. If I want to log in with another account, it doesn’t work fully.

    1. Krunal says

      Okay, go to your development account and make the app live and then again try to logged in as another user.

  2. Gabriel Marquez says

    The step 10 works properly. Do you know if making your app and all its live features available to the general public wont have any security problems?

    1. Krunal says

      Nope, you just need to assign proper permissions required by the application and also there are so many different algorithms which you can secure your app, but some of them, you need to develop on your own.

  3. FredFlinstone says

    hi,
    very thanks for this great tutorial … everything is working fine, but … if I login via FB, user XY is logged into web, then I log out successfully. Meanwhile I check db-table “users” and user XY is added to db-table (name, email, password, remember_token).
    Then I try log as XY in via credentials – email/password, but error message is raised (These credentials do not match our records.)
    What is wrong? because this credential really exists in db-table “users”.

    1. Muhammad Akbar says

      Because you generated random password in the service, either you need the user to create a new password or keep using the facebook login

  4. Yogi Sadhewo says

    hi krunal, your tutorial was amazing. i have followed step by step, but i dont know why i can’t log in, the command says “These credentials do not match our records.”. i hope you read my comments and help me out once again thank you 😀

  5. jc says

    Class App\Http\Controllers\SocialFacebookAccountService does not exist

    1. Son Nguyen says

      Make sure you have this in file SocialAuthFacebookController.php

      use App\Services\SocialFacebookAccountService;

      1. Roslan Ramli says

        still in the controller $service is undefined

      2. Roslan Ramli says

        I am using laravel 5.6
        use App\Services\SocialFacebookAccountService; was pasted and not used:
        $service not defined

        1. Roslan Ramli says

          Sorry my bad, I forgot to inject $service

  6. Abhishek jain says

    Good post. Working properly… Thumbs up

  7. wlad says

    I followed the steps until 6 there I got an error window that says: URL LOCKED: An error occurred in the redirect because the url is not included … To what is this and what can I do. Thank you

  8. kyamasam says

    Awesome tutorial. Works as expected on a live server. Not tried it on local server though.

  9. Sarwan says

    I clone your code from github and use on localhost follow your instructions but I got error Can’t load URL: The domain of this URL isn’t included in the app’s domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.

    How I can sort this issue

    1. Krunal says

      You need to create an app in your facebook developer account.

  10. Sarwan says

    Thanks sir for reply.
    I sort previous issue.I have another issue when i using different facebook user then creating issue given below:

    SQLSTATE[23000]: Integrity constraint violation: 1048 Column ’email’ cannot be null (SQL: insert into `users` (`email`, `name`, `password`, `updated_at`, `created_at`) values (, Sarwan Pal, 23fa71cc32babb7b91130824466d25a5, 2018-02-09 07:20:40, 2018-02-09 07:20:40))

    but when i using facebook app generated by id then i not facing issue given above.

  11. Sarwan says

    Please reply sir
    If I want to log in with another account, it doesn’t work fully.

  12. somur ruteeb says

    Nice work,
    I did this in my website, but the weakness that if the user uses the mobile to login via facebook, he well redirect to facebook on broweser not the facebook app. Is there any idea if i can redirect to facebook app intead of broswer ??

  13. ajay says

    sir it is not return email i dont know what happen
    it is return name but not email i cant reach this problem please help me

  14. Saha says

    Hi, Many many thanks for this good tutorial. Everything is working fine .. But Now I want these randomly generate password send to user through his email. Now what can I do ?

  15. nico says

    Everything worked functionally except when it redirects me back to my site im still not logged in,

  16. Ghaith says

    Nice guide, this however can’t be tested longer as facebook now refuse authentication from a non https source. it is not possible to disable any new apps force https option. Any work around?

    Thanks for the help.

  17. Nandini says

    I got this error
    Insecure Login Blocked: You can’t get an access token or log in to this app from an insecure page. Try re-loading the page as https://
    Please help me.

  18. fahmi says

    hye,did u know how to retrieve picture from socialite (fb/google) and make it as profile picture in laravel?

  19. saqib khan says

    Hello Kunal,

    Thank you for such an elaborated and made easy tutorial. It works all fine. But When I try to login with facebook ot gives error “You are not logged in: You are not logged in. Please log in and try again.”
    And if I manually am logged in then it gives error about invalid access or something. In short it is not logging in from website. Please help.

    Thanks

  20. veerapandian says

    I got this error
    Insecure Login Blocked: You can’t get an access token or log in to this app from an insecure page. Try re-loading the page as https://
    How can i solve this?

  21. Fen says

    It works on my site. However, google gives me an error about callback url:
    ——————————————————–
    URL:
    https://dance.zhengfen.ch/callback

    Error details

    Linked from

    Last crawled: 4/25/18
    First detected: 4/24/18
    Googlebot couldn’t access the contents of this URL because the server had an internal error when trying to process the request. These errors tend to be with the server itself, not with the request. More info.
    ————————————-
    How to avoid this? maybe change the method of the url ?
    Route::get(‘/callback’, ‘AuthFacebookController@callback’);
    -> Route::post’/callback’, ‘AuthFacebookController@callback’);

  22. surabhi says

    Thank You,very helpful post.

  23. Fredrik says

    Very nice guide! I wouldn’t use md5(rand(1,10000)) for passwords, though, a password like that can be brute-forced in less than 10000 attempts. Use md5(random_bytes(64)) instead.

  24. Jacek Chałupka says

    Great tutorial, thank You very much.

    I just would like to ask a question, as I am new to Laravel. Why did You put creating or getting user in service not in controller itself? Just so the controller code would be clearer or is there another reason?

  25. sayeed roshan says

    Awesome tutorial. Works fine for me,
    Facing only one challenge, if i am in either in cart or any other page page after login it should redirect to the particular page. How can I achieve this, Please help me

  26. Ronie Meque says

    Amazing tutorial. I’m usually lazy to comment thanking, but this time I just had to. Thanks!!!

  27. Roslan Ramli says

    I am getting error from this line from the controller
    $service is undefined

    1. Roslan Ramli says

      Sorry, my bad, I forgot to inject $service

  28. Roslan Ramli says

    Your instructions and code are good. Thanks, manage to deploy on a new live digitalocean host.

    However on my development env, I am using ubuntu on windows and set one of the hosts as dev.company.biz. So I manage to get laravel with ‘php artisan serve’landing page on dev.company.biz.

    So, is it possible on the callback to return to dev.company.biz

  29. Roslan Ramli says

    How do I get facebook’s avatar into the database. Please help me cause I just cannot proceed, since I have tried it since morning. I tried adding the below code to SocialFacbookAccountService.php

    $user = User::create([
    ’email’ => $providerUser->getEmail(),
    ‘name’ => $providerUser->getName(),
    ‘password’ => md5(rand(1,10000)),
    ‘avatar’ => $providerUser->getAvatar() // added code

    ]);
    but I get null in the database.

  30. Julian says

    Nice posts! works really well

  31. demet Akyol says

    Hello ,I have a question.
    If the user is not registered, we are generating a random password and the user how to know use this password at the next login.

  32. swati says

    login with only one email ..how we login with another email??

  33. Kishan Paneri says

    I got error like this

    Can’t Load URL: The domain of this URL isn’t included in the app’s domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.

  34. Pat says

    Whats the best way to add twitter into this setup. I have facebook up and working now but would like to extend it

    1. Gaurav says

      help me to resolve this issue, i have done everything, installed certificates and all.
      still its giving same error..

      Insecure login blocked: You can’t get an access token or log in to this app from an insecure page. Try re-loading the page as https://

  35. gaurav says

    help me to resolve this issue, i have done everything, installed certificates and all.
    still its giving same error..

    Insecure login blocked: You can’t get an access token or log in to this app from an insecure page. Try re-loading the page as https://

  36. Shahid Hussain says

    How can i sove this issue login to facebook in laravel app
    Insecure Login Blocked: You can’t get an access token or log in to this app from an insecure page. Try re-loading the page as
    i have setup facebook login/setting/oauth redirect URI to but still an error

  37. Rogério Aguiar Hanssen says

    Hi, i’m using Laravel 5.7 and I’m getting an error that user_id can’t be null when trying to create SocialFacebookAccount. Regards.

  38. Roger Silva Santos Aguiar says

    Hello! I followed step by step, but when I try to login with facebook, I have the following error:

    SQLSTATE[42703]: Undefined column: 7 ERROR: column “id” does not exist LINE 1: …t”, “created_at”) values ($1, $2, $3, $4, $5) returning “id” ^ (SQL: insert into “social_facebook_accounts” (“provider_user_id”, “provider”, “user_id”, “updated_at”, “created_at”) values (2161413204171060, facebook, 1, 2019-03-08 15:26:57, 2019-03-08 15:26:57) returning “id”)
    Previous exceptions
    SQLSTATE[42703]: Undefined column: 7 ERROR: column “id” does not exist LINE 1: …t”, “created_at”) values ($1, $2, $3, $4, $5) returning “id” ^ (42703)

    I checked my code, it is everything equal your code, can you help me please?

  39. Priyanka says

    Hi,
    Amazing tutorial… I have integrated your code in my applications and its working great. However, when the user is redirected back from Facebook callback url it doesn’t show the user as logged in to the application. The user is redirected to the homepage but restricted pages that should only be visible to authenticated users are not displayed here. Any guesses what should i do?

    Thanks

  40. souvik says

    site url is not there in facebook developer

  41. David Blackwell says

    Hi, thanks for your great tutorial.
    It works well, I am happy with your tutorial.
    I have just one question, if I am going to integrate this Facebook login with mobile app, what should I do in API side?
    Happy coding,

    Regards.

  42. jasbir singh says

    Amazing tutorial, i set up facebook login in just one hour.

    Thanks author

  43. Ruchita Puri says

    Hi,

    I implement the above code same as it is. The difference is that i install laravel version 6.3 instead of 5.4.
    But i am getting error.

    When i click on “login with facebook” button, it goes to http://localhost:8000/callback?code=randomstring&state=randomstring. on this page it shows error like “Laravel\Socialite\Two\InvalidStateException”.

    I tried: config/session.php change ‘domain’ => env(‘SESSION_DOMAIN’, null), to ‘domain’ => env(‘SESSION_DOMAIN’, ‘http://localhost:8000/’).

    Still not worked for me. please tell me what is the issue ASAP

  44. Ishrat Ali says

    how to do facebook login with laravel api?

Leave A Reply

Your email address will not be published.

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