OmniAuth for facebook
I am trying to use this railscast episode to provide authentication via twitter http://railscasts.com/episodes/开发者_运维百科235-omniauth-part-1
I'm wondering whether it is possible to use omni auth to login with facebook as well?
Also, I wanted to use the HTML OpenID selector but the demo doesn't have facebook button and their FAQ suggests they don't have support for facebook, however, SO Authenticate page does show facebook as one of the buttons. The openid selector that SO uses is custom?
just add to you omniauth.rb credentials for facebook
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'CONSUMER_KEY', 'CONSUMER_SECRET'
end
In you session or authentication action(where you deal with twitter login) add extra logic for facebook.
As the other answers have said, if you want to use omniauth with facebook, then simply follow Mikhail's answer, (you get the consumer key and secret by registering with facebook). If you follow that pattern, you will actually be authenticating with facebook via OAuth2 and not via OpenID.
If you want to use omniauth with an OpenID provider like google for example, the pattern is slightly different e.g.:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :openid, ActiveRecordOpenidStore::ActiveRecordStore.new, :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end
OpenID requires a "store" to store associations and nonces that get created during the authentication process (in the above case we're using an ActiveRecord based OpenID store). With the above configuration going to the following url:
${RAILS_ROOT}/auth/google
Should kick off the OpenID authentication process against google. If you want to use a different OpenID provider to authenticate against, you will need to alter the :name
and :identifier
fields appropriately.
login url for facebook - railsroot/auth/facebook
login url for twitter - railsroot/auth/twitter
in your omniauth.rb initialiser
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, ' consumerkey ', 'consumer-secret '
provider :facebook, 'api-key' ,'api-secret', {:scope=>'publish_stream,offline_access,email'}
end
use your own scope access permissions
精彩评论