codenitive / laravel-oneauth

OAuth and OAuth2 Auth bundle for Laravel

Home Page:http://bundles.laravel.com/bundle/oneauth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Login with Facebook keeps registering

michaelaguiar opened this issue · comments

It seems that my "Login with Facebook" button, rather then determining weather to login or register, it always registers and duplicates that user in the database. user_id in the oneauth_clients table is also always zero.

What can I be doing wrong?

that is just weird, because provider and uid are index as unique so it should be impossible to get the following error

Oh no, the entry in oneauth_clients doesn't duplicate. When I login with Facebook, it always redirects me to the registration url, and re-registers the user, even though they are already registered. So it duplicates it in my Users table.

So it simply the matter of user is not logged in as a user. Well because
OneAuth doesn't do that automatically for you unless you code it to do
that. Try viewing this video tutorial if that what you need <
http://www.youtube.com/watch?v=xlUFiZhwFiE>

On Thu, Jan 10, 2013 at 8:42 AM, Michael Aguiar notifications@github.comwrote:

Oh no, the entry in oneauth_clients doesn't duplicate. When I login with
Facebook, it always redirects me to the registration url, and re-registers
the user, even though they are already registered. So it duplicates it in
my Users table.


Reply to this email directly or view it on GitHubhttps://github.com//issues/37#issuecomment-12075183.

Oh no that's not it. I mean I hit login with Facebook, I authenticate with facebook, and it always redirects me back to the registration url from urls.php - in which I have it create a new user and login. I already have a login function, but oneauth just isn't doing the redirect to the login url?

Because OneAuth DOESN'T CREATE A USER. Let me requote my previous response.

Well because OneAuth doesn't do that automatically for you unless you
code it to do that.

I know, it redirects to the register URL, set in your urls.php, which I point to my code that creates the user. What I'm saying, is it never goes to the login URL, it's always register no matter how many times I trigger it.

Sent from my iPhone

On Jan 9, 2013, at 7:58 PM, Mior Muhammad Zaki notifications@github.com wrote:

Because OneAuth DOESN'T CREATE A USER. Let me requote my previous response.

Well because OneAuth doesn't do that automatically for you unless you
code it to do that.

On Thu, Jan 10, 2013 at 10:52 AM, Michael Aguiar
notifications@github.comwrote:

Oh no that's not it. I mean I hit login with Facebook, I authenticate with
facebook, and it always redirects me back to the registration url from
urls.php - in which I have it create a new user and login. I already have a
login function, but oneauth just isn't doing the redirect to the login url?


Reply to this email directly or view it on GitHubhttps://github.com//issues/37#issuecomment-12078473.


Reply to this email directly or view it on GitHub.

Know what I mean? I might not of explained properly. How do I make it redirect to the login URL set in urls.php if the user is already registered? Is it supposed to always redirect to register, and I have to code it to login if the user already exists?

Any example of your code?

On Thu, Jan 10, 2013 at 11:42 AM, Michael Aguiar
notifications@github.comwrote:

I know, it redirects to the register URL, set in your urls.php, which I
point to my code that creates the user. What I'm saying, is it never goes
to the login URL, it's always register no matter how many times I trigger
it.

Sent from my iPhone

On Jan 9, 2013, at 7:58 PM, Mior Muhammad Zaki notifications@github.com
wrote:

Because OneAuth DOESN'T CREATE A USER. Let me requote my previous
response.

Well because OneAuth doesn't do that automatically for you unless you
code it to do that.

On Thu, Jan 10, 2013 at 10:52 AM, Michael Aguiar
notifications@github.comwrote:

Oh no that's not it. I mean I hit login with Facebook, I authenticate
with
facebook, and it always redirects me back to the registration url from
urls.php - in which I have it create a new user and login. I already
have a
login function, but oneauth just isn't doing the redirect to the login
url?


Reply to this email directly or view it on GitHub<
https://github.com/codenitive/laravel-oneauth/issues/37#issuecomment-12078473>.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/37#issuecomment-12079491.

Did you login the registered user before linking it with Facebook, or you
are not logged and click Facebook button?

On Thu, Jan 10, 2013 at 11:46 AM, Michael Aguiar
notifications@github.comwrote:

Know what I mean? I might not of explained properly. How do I make it
redirect to the login URL set in urls.php if the user is already
registered? Is it supposed to always redirect to register, and I have to
code it to login if the user already exists?


Reply to this email directly or view it on GitHubhttps://github.com//issues/37#issuecomment-12079534.

I just found the "secret" column in the table is null.
Yes, so on the login screen before login, I hit "Login with Facebook". It goes to facebook, I authenticate, and it sends me back to my register url. Is there something I need to do to send back to fb for the secret key to be store in oneauth_clients?

Gist to follow

crynobone: I don't think my question was answered. Do I need to do anything to start.php?

I had this problem, I wasn't updating my oauthclients table with the user ID so when it came to login the user was not found and so would register instead.

Added this code to my register action straight after creating the user:

$user->save();
// update oneauthdetails
$oneauth = Oneauthclient::where_provider($user_data['provider'])
        ->where_uid($user_data['info']['uid'])->first();

$oneauth->user_id = $user->id;
$oneauth->save();

My code might be a bit different but basically for me, I had to update the oneauthclient table with the new users' id

Yep, I found that this is what solved my problem. Thanks!