I have a few questions that I can't answer with the Laravel official doc.. I am trying to use this practical Facebook (or other SNS) login that we see everywhere.
I had looked for a good tutorial about it but I couldn't find better than that one.
I followed it and I think I pretty much understand the process involved in here.
- Our website goes to FB
- We authenticate ourselves on FB
- We then get redirected back to our app. With a 'token' saved somewhere and the user data.
But then what ? How do we access the protected part of our website ? I mean how do we pass the, out of the box middleware, that we already have ?
Because I have my FB login button on the standard login page (www.mywebsite/auth/login) but then what I don't quite understand is what callback in my service.php should I have ?
Currently
'facebook' => [
'client_id' => '12321452415',
'client_secret' => '675f2d7f77232b0fb20762261db6dcd072',
'redirect' => 'http://mywebsite/',
],
But off course if I call my main page I just got redirected to my login page again because of the middleware.. right ?? I mean did I do something wrong or I just didn't do enough ?
Hope I am enough clear..
Any help very much appreciated
The redirect you have defined under services.php should be a route of your website lets say http://website.com/callback ; once you have authenticated your request on facebook you will be redirected back to this route. If you are working with the basic facebook app without any extra permissions then you will get Facebook name of the user, fb profile id, photo and few extra details as mentioned in the tutorial you have referred. You can utilize these details to authenticate user on your website e.g you have a table users with one extra column i.e fb_id once you get response back from facebook you check your db if the fb_id you got from response exist in the database ? if yes then use
if you do not get any record matching this fb_id you insert a new record in the database and then loginUsingId
I hope I am clear enough with this.
Ok, I am sure I can do much better than that but I have something working (after scratching my head a couple of time)
My routes:
And my controller:
And my login page:
Any improvements is welcomed. I know it's not perfect but it might help someone :)