Andy Harvey
Andy Harvey

Reputation: 12663

Implementing oauth in a Rails app: one user model or two (user + authentication)?

On my journey to learning Rails, I'm making my first foray into oauth territory. I have a User model, and plan to allow users to connect to several services. I expect this will be a fixed list of services, i.e. I don't anticipate adding new authentication services in the future (though never say never, right?).

So, I can see two ways of proceeding.

  1. Have an uber User model that, as well as holding username, password, etc also stores fb_uid, twitter_uid, etc and any data pulled from those services.

  2. Have a User model, and an associated Auth_Services model. Username, password, etc goes in Users. Uid, user_id, provider name, oauth data, etc goes in Auth_Services.

I can see advantages and drawbacks in both approaches. I can see opinions with regard to normalized database design with both approaches.

So my question, for people who have done this before, which route did you use, and why? What issues did you run into, and what should I be thinking about or planning for when making a decision?

Thanks for helping me learn!

Upvotes: 0

Views: 213

Answers (1)

wachichornia
wachichornia

Reputation: 1188

If there is even the slightest possibility you will add further authentications, gotta go with the two models. That was my reason anyway.

Upvotes: 1

Related Questions