Giter VIP home page Giter VIP logo

devise-twitter's Introduction

devise-twitter

Devise-twitter adds Sign in via Twitter and Connect your account to Twitter functionality to your devise app.

It requires at least Devise 1.1 and ONLY works with Rails 3.

Current status

Devise-twitter currently supports Sign in via Twitter and Connect your account to Twitter, but no proper API for Connect your account to Twitter exists so far.

This plugin is in use in an upcoming product and continues to be improved.

Installation

Simply add devise-twitter to your Gemfile and bundle it up:

gem 'devise-twitter'

Run the generator, supplying the name of the model (e.g. User)

$ rails generate devise:twitter user

Add your OAuth credentials to config/initializers/devise_twitter.rb

Devise::Twitter.setup do |config|
  config.consumer_key = <YOUR CONSUMER KEY HERE>
  config.consumer_secret = <YOUR CONSUMER SECRET HERE>
  config.scope = :user
end

Modify your user model like so

class User < ActiveRecord::Base
  # To use devise-twitter don't forget to include the :twitter_oauth module:
  # e.g. devise :database_authenticatable, ... , :twitter_oauth

  # IMPORTANT: If you want to support sign in via twitter you MUST remove the
  #            :validatable module, otherwise the user will never be saved
  #            since it's email and password is blank.
  #            :validatable checks only email and password so it's safe to remove

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable :twitter_oauth

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
end

Modify the generated routes (in config/routes.rb) to your liking

Application.routes.draw do
  devise_for :user do
    match '/user/sign_in/twitter' => Devise::Twitter::Rack::Signin
    match '/user/connect/twitter' => Devise::Twitter::Rack::Connect
  end
  ...

Run the generated migration

$ rake db:migrate

Signing in via Twitter

When signing in via Twitter, after authorizing access on www.twitter.com, devise-twitter will sign in an existing user or create a new one, if no user with these oauth credentials exists.

Connect your account to Twitter

Devise-twitter supports adding Twitter credentials to an existing user account (e.g. one that registered via email/password) but currently the API to expose this feature is far from perfect:

After navigating to /user/connect/twitter and authorizing access on www.twitter.com, devise-twitter checks if there is another user with the same twitter handle. If not devise-twitter adds twitter handle and oauth credentials to the current user and saves.

If another user with the same twitter handle is found devise-twitter sets the session variable warden.user.twitter.connected_user.key to the id of this user. Your application can check if this variable is set and display an option to merge the two users.

if connected_user = session['warden.user.twitter.connected_user.key'].present?
  connected_user = User.find(connected_user)

  # Ask user if she/he wants to merge her/his accounts
  # (or just go ahead and merge them)
end

If you have any idea how to improve it, please message me.

Database changes

The generated migration adds three fields to your user model:

change_table(:users) do |t|
  t.column :twitter_handle, :string
  t.column :twitter_oauth_token, :string
  t.column :twitter_oauth_secret, :string
end

add_index :users, :twitter_handle, :unique => true
add_index :users, [:twitter_oauth_token, :twitter_oauth_secret]

Currently the names of these fields are hard coded, but making them customizable is on the roadmap.

Acknowledgements

Thanks to

  • Daniel Neighman for creating warden, the framework Devise uses
  • Jose Valim for creating Devise
  • Pelle Braendgaard for implementing oauth support in Ruby
  • Roman Gonzalez for creating warden_oauth, the framework devise-twitter uses
  • all the other giants who's shoulders this project stands on

Meta

devise-twitter's People

Contributors

msch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

devise-twitter's Issues

Getting "undefined method `twitter_handle=' for nil:NilClass on auth

I've just installed the devise-twitter gem on the following system:

Ubuntu 10.04
ruby 1.8.7 (2010-01-10 patchlevel 249)
Rails 3.0.0
Warden 0.10.7
oauth 0.4.3
devise (master, 9/13/2010)
Nginx fronting Passenger

I'm adding Twitter to a sample app that I put together that does Facebook authentication using Devise's OAuth2 features.

When I attempt to authenticate using Twitter, I am correctly prompted for my Twitter credentials. But after I submit correct credentials, the postback fails with an error. Specifically:

undefined method `twitter_handle=' for nil:NilClass

The top of the stack trace is:

activesupport (3.0.0) lib/active_support/whiny_nil.rb:48:in method_missing' devise-twitter (0.1.1) lib/devise/twitter/warden.rb:12:in_find_user_by_access_token'

and examination of the code indicates that @env['warden'].user is nil, which is causing this issue.

I've attached env['warden'] to the end of this comment. Any idea what's going on here? Happy to provide more info as necessary.

env['warden']: http://pastie.org/1157066

Does not log user in after doing a sign_in

This only happens when a user is registering for the first time.

Devise-twitter does not log the user in after navigating to /user/sign_in

It saves the user in the db, but does not log the user. To log the user in, the user would have to navigate to /user/sign_in a second time

Am I missing something or is this a bug?

error with warden 1.0

I am getting this error when starting my app

/usr/local/rvm/gems/ruby-1.9.2-p0/gems/warden-1.0.0/lib/warden/strategies.rb:11:in `add': authenticate! is not declared in the :twitter_oauth strategy (NoMethodError)

uninitialized constant Devise::Models::TwitterOauth

Hello there,

I've installed:

devise (1.4.2)
devise-twitter (0.1.1)

and have followed the instructions on the devise-twitter page.

I'm calling: http://localhost:3000/user/sign_in/twitter

and get

NameError

uninitialized constant Devise::Models::TwitterOauth

app/models/user.rb:12

class User < ActiveRecord::Base

To use devise-twitter don't forget to include the :twitter_oauth module:

e.g. devise :database_authenticatable, ... , :twitter_oauth

IMPORTANT: If you want to support sign in via twitter you MUST remove the

:validatable module, otherwise the user will never be saved

since it's email and password is blank.

:validatable checks only email and password so it's safe to remove

Include default devise modules. Others available are:

:token_authenticatable, :confirmable, :lockable and :timeoutable

devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :twitter_oauth

Setup accessible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me
end

What am I missing?

Thanks
Thomas

Not working with mongoid

I'm getting error because the gem is using an activerecotd specific find. I've changed it by a monkey patch like this. but it's better to use a general format of finder which is compatible with most of ORMs

def self.find_by_twitter_oauth_token_and_twitter_oauth_secret(*vals)
  User.find(:first, :conditions => { :twitter_oauth_token => vals[0], :twitter_oauth_secret => vals[1]  })
end

Working with mongoid error unitialized constant

I'm workind with mongoid (learning) and devise
i follow up the "how to" but when i try to test i have this error
uninitialized constant Devise::Twitter

This error occurred while loading the following files:
config/routes.rb

Mi routes.rb

Weird::Application.routes.draw do
root :to => "home#index"
devise_for :users do
match '/users/sign_in/twitter' => Devise::Twitter::Rack::Signin
match '/users/connect/twitter' => Devise::Twitter::Rack::Connect
end
resources :users, :only => :show
end

I can't find the problem.... ideas?

Receiving a 401 Unauthorized error

I'm encountering a 401 Unauthorized error when oauth tries to acquire a request token. I've been trying to figure out what the issue is for the past hour with no luck.

I've got my consumer_key and consumer_secret all setup in devise_twitter.rb. What else could I have wrong?

Thanks.

Store Twitter ID as unique identifier

Wouldnt it be wise to store the twitter id and have that as the primary field instead of the twitter_handle? If a user decides to change his twitter name in twitter.com, then this gem will create a another user record on the db.

Second, how does the app keep track of users who change their twitter handle? At least with the twitter id, this will always be unique never changing...

Rollback not working properly

If one decides to rollback. An error appears:

rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR: column "string" of relation "users" does not exist
: ALTER TABLE "users" DROP "string"


The problem is at:

class AddDeviseTwitterFieldsToUsers < ActiveRecord::Migration

......

change_table(:users) do |t|
  t.remove :twitter_handle, :string
  t.remove :twitter_oauth_token, :string
  t.remove :twitter_oauth_secret, :string
end

end

it should be:

change_table(:users) do |t|
  t.remove :twitter_handle
  t.remove :twitter_oauth_token
  t.remove :twitter_oauth_secret
end

The above works if changed. Thought you might want to look at this...

email error

I will try to explain my error with examples

I have one registered user with devise (uokesita, [email protected], etc, ...)

I try to sign in with twitter and my account @uokesita everthing works fine

Then I try to sign in with other twitter account ex: @coders_vzla it creates a new devise user with no email. also works fine

Then if i try to sign in with another twitter account ex: @otheraccount it tries to create a new devise user with no email but it complains since there is another register with no email

http://cl.ly/3C2N0g0C0T0e1Z0x2w2k

http://cl.ly/3g0c3T0s3u322Y3A2L37

How can i solve this?

How to save twitter data on local db

Hi, great plugin! And I hope that the development goes on for this gem.

I am wondering. I am able to do a sign-in with Twitter. My db stores twitter_handle, twitter_oauth_token and twitter_oauth_secret. However, my user model also has other fields such as: full_name, description, url, followers_count, friends_count, photo_caption, photo_file_name, etc, which are all fields from the user twitter api (http://dev.twitter.com/doc/get/statuses/show/:id)

I need to populate these fields in my local db. How should this be done?

Doesn't play well with the jnunemaker/twitter gem

I'm using devise-twitter only for connecting my devise user to Twitter. Since devise-twitter does not have hooks to perform status updates, I attempted to use the twitter gem by jnunemaker. However, since the jnunemaker's class is named Twitter that collides with the warden strategy class name as it attempts to use :twitter (passed from the Devise::Twitter.set) to check if a class is available and that causes errors regarding authenticate! method not being available.

It may make sense to use :devise_twitter as the strategy name so that it doesn't collide with the twitter gem class.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.