My application need a twitter account to create an account and authentify. Then, the user can link any other Twitter accounts as he like. So, a user has ONE main twitter account which allow him to connect to my app, then, he can browser all the accounts he has previously linked in the app. My question is about the login process on Twitter side.
First, I've thinked about setting force_login
only when linking new account. This way, the user does not have to reconnect on Twitter each time he want to connect to my app. And, when he want to link another account, force_login
force him to chose the right account. The problem is that Twitter stay connected to the last authentified account. So, if the user logout from my app just after linking another account, then login with twitter, he login with the second account, and create a new user on my app. Exemple:
User has two twitter accounts : @a and @b. He's authentified to Twitter with @a. He signup to my app, Twitter shows him the permissions asked by my app, user accept, he's redirected to my app, a new User which can auth with @a is created.
Then, he link @b account. Thanks to force_login
, Twitter asks him for credentials. User login to @b, Twitter asks permissions, then, the account is linked to the user on my app. We now have a user who can auth with @a and who is linked to @b.
Then, session on my app is over, user needs to reconnect. Because there is no force_login
, Twitter sees he's already connected with an account which authtorised my app, so connection is accepted without any action from the user. But, what nobody sees is that user was connected with the last account : @b. So, I get a signin action with @b, which means to a new user creation.
I now have two users : User1 which can auth with @a and is linked to @b, and User2 which can auth with @b. And my user doesn't understand where is its @a account.
So my question is : do I have to set force_login
anywhere ? Or is there another way to tell Twitter to not authentify when linking an account?
It's not so easy. Keep in mind that many user should manage the same account. A simple example : @Maurice and @Roy are members of @ReynholmIndustries corporation. They will create their own account on my service with their own account on twitter. So on my service, I will have User1 which can connect with @Maurice and User2 which can connect with @Roy. Then, @Maurice will add @ReynholmIndustries account to my service. So, after login in with @Maurice, he can manage @Maurice and @ReynholmIndustries. Then, @Roy will add @ReynholmIndustries too. Nobody can login with @ReynholmIndustries but @Maurice and @Roy, with their own account can manage it. And then, it's obviously possible that someone create a new user by signing up with @ReynholmIndustries.
The difficulty is when adding a new account : UserA signin to my service by signin in on Twitter. He's now authentified as @Maurice and on my service as UserA and can manage @Maurice. Then, he adds @ReynholmIndustries by signin in Twitter as @ReynholmIndustries. He's now authentified on my service as @Maurice, can manage @Maurice and @ReynholmIndustries but, on Twitter, he's now authentified as @ReynholmIndustries. Later, he lose auth on my service and he click on signin button. He's redirected on twitter oauth form and we have now two options :
By writing this, I realise it is not a problem : if my service had a local auth, user should have too to type login/pass everytime he lose auth… maybe force_login is really the correct option. What do you think about all of this?
For me it looks like your problem is not related to twitter at all. You just need to handle the login / sign up process properly in your application.
Here is what happens, according to your description:
Now you say "So, I get a signin action with @b, which means to a new user creation.". Why so? Twitter knows nothing about your application, but you do know it.
What you want to do here is just search through your database, find that you already have the "twitter @b" account and it is linked to "UserA". Then you just login the "UserA" into your application instead of creating the new user (you anyway don't want to have different users with the same twitter account, so twitter account id should be unique in your database).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With