Skip to content

Instantly share code, notes, and snippets.

@chyld
Created December 7, 2012 15:49
Show Gist options
  • Save chyld/4234102 to your computer and use it in GitHub Desktop.
Save chyld/4234102 to your computer and use it in GitHub Desktop.
add gem omniauth-twitter
**********************************************************************************
initialization file:
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ENV['TW_CON_KEY'], ENV['TW_CON_SEC']
end
**********************************************************************************
routing:
match '/auth/:provider/callback' => 'sessions#create'
match '/auth/failure' => redirect('/')
match '/signout' => 'sessions#destroy'
**********************************************************************************
session controller:
def create
user = User.from_omniauth(env["omniauth.auth"])
# save user id in session
# redirect to home
end
def destroy
# set id to nil
# redirect to home
end
**********************************************************************************
user model:
def self.from_omniauth(auth)
where(auth.slice("provider", "uid")).first || create_from_omniauth(auth)
end
def self.create_from_omniauth(auth)
# create a new user, save provider, uid and name/nickname
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment