Cannot use facebook for authentication: undefined method 'web_server' for OAuth2?

An attempt to allow users to log in / register on Twitter and Facebook. Twitter works without problems, but the strategy for Facebook is different.

undefined method `web_server' for #<OAuth2::Client:0x00000005211d58>

Tracking shows

oa-oauth (0.0.1) lib/omniauth/strategies/oauth2.rb:18:in `request_phase'
oa-oauth (0.0.1) lib/omniauth/strategies/facebook.rb:28:in `request_phase'
oa-core (0.0.5) lib/omniauth/strategy.rb:25:in `call!'
oa-core (0.0.5) lib/omniauth/strategy.rb:19:in `call'
oa-core (0.0.5) lib/omniauth/builder.rb:22:in `call'
warden (1.0.5) lib/warden/manager.rb:35:in `block in call'
warden (1.0.5) lib/warden/manager.rb:34:in `catch'
warden (1.0.5) lib/warden/manager.rb:34:in `call'

Has anyone else experienced this?

ps. I use the following gems:

gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'oauth2'

I do not use the omniauth full gem, as its address dependencies conflict with other gems.

+5
source share
3 answers

facebook_oauth (https://github.com/moomerman/facebook_oauth) rails. , , , oauth2 . , . :

Gemfile

gem 'oauth2'

bundle update

login_via_facebook uri , oauth-, - :

oauth_client = OAuth2::Client.new(APPLICATION_ID, APPLICATION_SECRET, {
    :authorize_url => 'https://www.facebook.com/dialog/oauth'
})

redirect_to oauth_client.authorize_url({
    :client_id => APPLICATION_ID,
    :redirect_uri => YOUR_REDIRECT_URL
})

, scope param authorize_url:

redirect_to oauth_client.authorize_url({
    :client_id => APPLICATION_ID,
    :redirect_uri => YOUR_REDIRECT_URL,
    :scope => 'offline_access,email'
})

, YOUR_REDIRECT_URL ( login_via_facebook_callback), - :

oauth_client = OAuth2::Client.new(APPLICATION_ID, APPLICATION_SECRET, {
    :site => 'https://graph.facebook.com',
    :token_url => '/oauth/access_token'
})

begin

  access_token = oauth_client.get_token({
      :client_id => APPLICATION_ID,
      :client_secret => APPLICATION_SECRET,
      :redirect_uri => YOUR_REDIRECT_URL,
      :code => params[:code],
      :parse => :query
  })

  access_token.options[:mode] = :query
  access_token.options[:param_name] = :access_token
  facebook_user_info = access_token.get('/me', {:parse => :json}).parsed

rescue Error => e

  # You will need this error during development to make progress :)
  #logger.error(e)

end

facebook_user_info !

+4

, :

  • / , gemfile:

gem 'omniauth',: git = > 'git://github.com/intridea/omniauth.git'

  • rails, Twitter/Facebook , :

rails new APP_NAME -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-mongoid-omniauth-template.rb -T

: https://github.com/RailsApps/rails3-mongoid-omniauth/wiki/Tutorial

+1

here I came across an example application that demonstrates the use of omniauth along with authlogic https://github.com/madhums/omniauth-authlogic-demo hope this helps

0
source

All Articles