How should I managed a database for register/log in with Facebook & Twitter - mysql

I am creating an iOS App which the user will be able to login to via his account with our website (internal), or via Facebook or Twitter.
What I would like to know is how should I manage the database in order to verify his Facebook / Twitter account with his internal account on my website?
I.e When the user logs in via his internal account, I just run a simple authentication check to see if his username and password are valid. However with Facebook and Twitter, I obviously can't do this as I don't have access to the user's password.
Thanks in advanced.

my suggestion is that you would create a new table for each of the login types and connect it to your users/members table.
for example - for facebook login you would have a facebook_users table to hold the user's data (such as name, pic and most important - fbid)
than add a column named facebook_user_id to your existing members table.
in order to get the logged user from facebook you don't need to access his password... you should use the Facebook JS SDK and specifically the FB.getLoginStatus and FB.login function...
offcourse my suggestion is only one of many applicable ways to accomplish the task

Save fbid instead of fb-login user_name (you can keep both) of the user in your internal login table - A unique mapping exists (I'm sure something similar exists for twitter as well). Why do you need fb password for it?
Moreover, you run the check on internal table to authenticate user account, but when using login from fb or twitter, isn't the user already authenticated?

Related

How do I SILENTLY create external user under enterprise account? No invite

Is there a way to create an external user account under an enterprise account silently, where there is no accept/email invite needed?
Use Case:
User becomes a member of our web site, we call API and provision grant them silently which creates an external user under our enterprise account.
Any code axample? Silently and without invite is the key thing here. Thanks!
There isn't a way to do this. The user doesn't have a password at creation time and needs to set one by going to the website via the email confirmation link.
Could you perhaps explain why you don't want the email to be sent, and what your user workflow looks like?

Integrating multiple user account tables

I have three websites: a.example.com, b.example.com, and c.net. Each was built a couple years after the other and all have their own users table.
I want to integrate these sites together so that I can login with a single username/password combo and have access to all three sites just by clicking links without having to login again.
I've never done an integration like this before, so looking at two angles:
1) Create another website, 'd.net' where new accounts can be created. If you login to one of the original three sites, it asks you for your d.net account. If you dont have one it asks you to make one. In your 'account settings' on d.net, you can 'add sites' to your account by entering your old username and password for them. Sound reasonable?
2) Solving the technical problem of being able to one-click login to another of the three sites if i'm already logged into d.net. Afaik, cookies with a session ID can't be shared across domains. So... maybe generate a token and save it to the database. Send token over GET to another website, which can check the token, log the user in, and then delete the token. Sound about right?
Have you looked at OpenID?
http://en.wikipedia.org/wiki/OpenID
Don't have to re-invent the wheel.

Facebook OAuth getting only email, possible?

I'm busy to enable login stuff via facebook oauth on my website, but the only thing I want to get is the email of the user.
I saw in dev docs the 'scope=email' but, it seem's mandatory for the user to allow access to anything about him.
is there's a way to ask him to grant access only on his email ?
No. The bare minimum that your app will request from the user is his Basic Information, followed by your extended permissions (in your case, his email address).
nope. email is a so called extended permission. so you have to get the basic set of data of the user. (like: name, fbid, gender, locale).

designing a database with facebook id and normal sign ups

So I am creating a website that basically allows user to sign up using their facebook account/facebook connect and just a traditional sign up (username, password). Now currently my table looks like this:
uid, username, password, email
I was thinking of how can I change this table structure to incorporate the facebook account connect as it doesn't have any username or password in it, should I just store the email and leave the username and password blank? How do other sites that have such login structure save this information?
You'll really want to store the facebook_id as well, for which I recommend using a bigint.
You might also want to add a status column that indicates whether this user account was created via email address or facebook_id, so that at login time you know which to check. Alternately, you could just check the one that you have credentials for.
This is a fairly open ended question, and the answers depend on what your trying to accomplish, and the use cases you're trying to address. Some general thoughts/suggestions: You should also store the Facebook ID as a separate column. You can leave the username blank, as the Facebook ID can uniquely identify the user, or you can use the email as the username. If you use only Facebook connect, you don't need the password since you can use the JS SDK to make sure the user has a valid Facebook login session.

Facebook connect database transaction help

I am trying to implement a simple login system with facebook, but I need users to pick a username. What I was thinking was to get all the information I need from facebook, request permissions, then add the information to the database, redirect to a form asking for a username and then add that to the database, to the same entry.
I think a transaction is needed so I don't end up with any half completed database entries. But I've only ever used them on the same page, so I'm wondering if this is safe? If it fails then there is no point where I would be telling the database to roll back the changes and it would be with a transaction open.
Is this right or will it be ok?
I think you made it more complicated than it should be :)
No need to enter facebook id into database before username as you can always grab it later.
Forward user to login screen (or better just open login popup using javascript FB API)
Once user is logged in forward them to username picking page (or better do javascript popup without page redirect)
When user is entered username request the current user id from facebook on server side (by either using graph api or fql) and then if everything is ok enter this record to database.