title: Rails & Oauth: multiple providers
body: <p>I've got an app that permits users to post to LinkedIn, Facebook, and Twitter. I'd like to authorise each user's account with as many of those providers as the user would like.</p>
  
  <p>My user model has some columns to help authorise one provider at a time:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    ...
    attr_accessible :provider, :uid, :oauth_token, :oauth_expires_at, :oauth_token_secret, :access_token, :access_token_secret ...
    ...
  end
  </code></pre>
  
  <p>Here's the model method:</p>
  
  <pre><code>def self.from_omniauth(user, auth)
    user.provider = auth.provider
    if auth.provider == "facebook"
      user.uid = auth.uid
      user.oauth_token = auth.credentials.token
      user.oauth_expires_at = Time.at(auth.credentials.expires_at)
    elsif auth.provider == "twitter"
      # not sure which one twitter uses
      user.oauth_token = auth["credentials"]["token"]
      user.oauth_token_secret = auth["credentials"]["secret"]
      user.access_token = auth["credentials"]["token"]
      user.access_token_secret = auth["credentials"]["secret"]
    end
    user.save!
  end
  </code></pre>
  
  <p>And the controller auth method looks like this:</p>
  
  <pre><code>def authorise
    user = User.from_omniauth(current_user, env['omniauth.auth'])
    session[:user_id] = current_user.id
    redirect_to root_url
  end
  </code></pre>
  
  <p>Any help would be great! Really not sure how to proceed from here. Having x (3 in the above case, more to come) amount of <code>:provider</code> columns seems kinda ridiculous.</p>