Created
December 7, 2012 15:49
-
-
Save chyld/4234102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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