Giter VIP home page Giter VIP logo

omniauth-facebook's Introduction

OmniAuth Facebook  Build Status Gem Version

📣 NOTICE We’re looking for maintainers to help keep this project up-to-date. If you are interested in helping please open an Issue expressing your interest. Thanks! 📣

These notes are based on master, please see tags for README pertaining to specific releases.

Facebook OAuth2 Strategy for OmniAuth.

Supports OAuth 2.0 server-side and client-side flows. Read the Facebook docs for more details: http://developers.facebook.com/docs/authentication

Installing

Add to your Gemfile:

gem 'omniauth-facebook'

Then bundle install.

Usage

OmniAuth::Strategies::Facebook is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.

Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET']
end

See the example Sinatra app for full examples of both the server and client-side flows (including using the Facebook Javascript SDK).

Configuring

You can configure several options, which you pass in to the provider method via a Hash:

Option name Default Explanation
scope email A comma-separated list of permissions you want to request from the user. See the Facebook docs for a full list of available permissions: https://developers.facebook.com/docs/reference/login/
display page The display context to show the authentication page. Options are: page, popup and touch. Read the Facebook docs for more details: https://developers.facebook.com/docs/reference/dialogs/oauth/
image_size square Set the size for the returned image url in the auth hash. Valid options include square (50x50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), or large (about 200 pixels wide, variable height). Additionally, you can request a picture of a specific size by setting this option to a hash with :width and :height as keys. This will return an available profile picture closest to the requested size and requested aspect ratio. If only :width or :height is specified, we will return a picture whose width or height is closest to the requested size, respectively.
info_fields name,email Specify exactly which fields should be returned when getting the user's info. Value should be a comma-separated string as per https://developers.facebook.com/docs/graph-api/reference/user/ (only /me endpoint).
locale Specify locale which should be used when getting the user's info. Value should be locale string as per https://developers.facebook.com/docs/reference/api/locale/.
auth_type Optionally specifies the requested authentication features as a comma-separated list, as per https://developers.facebook.com/docs/facebook-login/reauthentication/. Valid values are https (checks for the presence of the secure cookie and asks for re-authentication if it is not present), and reauthenticate (asks the user to re-authenticate unconditionally). Use 'rerequest' when you want to request premissions. Default is nil.
secure_image_url true Set to true to use https for the avatar image url returned in the auth hash. SSL is mandatory as per https://developers.facebook.com/docs/facebook-login/security#surfacearea.
callback_url / callback_path Specify a custom callback URL used during the server-side flow. Note this must be allowed by your app configuration on Facebook (see 'Valid OAuth redirect URIs' under the 'Advanced' settings section in the configuration for your Facebook app for more details).

For example, to request email, user_birthday and read_stream permissions and display the authentication page in a popup window:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
    scope: 'email,user_birthday,read_stream', display: 'popup'
end

API Version

OmniAuth Facebook uses versioned API endpoints by default (current v5.0). You can configure a different version via client_options hash passed to provider, specifically you should change the version in the site and authorize_url parameters. For example, to change to v7.0 (assuming that exists):

use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
    client_options: {
      site: 'https://graph.facebook.com/v7.0',
      authorize_url: "https://www.facebook.com/v7.0/dialog/oauth"
    }
end

Per-Request Options

If you want to set the display format, auth_type, or scope on a per-request basis, you can just pass it to the OmniAuth request phase URL, for example: /auth/facebook?display=popup or /auth/facebook?scope=email.

Auth Hash

Here's an example Auth Hash available in request.env['omniauth.auth']:

{
  provider: 'facebook',
  uid: '1234567',
  info: {
    email: '[email protected]',
    name: 'Joe Bloggs',
    first_name: 'Joe',
    last_name: 'Bloggs',
    image: 'http://graph.facebook.com/1234567/picture?type=square&access_token=...',
    verified: true
  },
  credentials: {
    token: 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store
    expires_at: 1321747205, # when the access token expires (it always will)
    expires: true # this will always be true
  },
  extra: {
    raw_info: {
      id: '1234567',
      name: 'Joe Bloggs',
      first_name: 'Joe',
      last_name: 'Bloggs',
      link: 'http://www.facebook.com/jbloggs',
      username: 'jbloggs',
      location: { id: '123456789', name: 'Palo Alto, California' },
      gender: 'male',
      email: '[email protected]',
      timezone: -8,
      locale: 'en_US',
      verified: true,
      updated_time: '2011-11-11T06:21:03+0000',
      # ...
    }
  }
}

The precise information available may depend on the permissions which you request.

Client-side Flow with Facebook Javascript SDK

You can use the Facebook Javascript SDK with FB.login, and just hit the callback endpoint (/auth/facebook/callback by default) once the user has authenticated in the success callback.

Note that you must enable cookies in the FB.init config for this process to work.

See the example Sinatra app under example/ and read the Facebook docs on Login for JavaScript for more details.

How it Works

The client-side flow is supported by parsing the authorization code from the signed request which Facebook places in a cookie.

When you call /auth/facebook/callback in the success callback of FB.login that will pass the cookie back to the server. omniauth-facebook will see this cookie and:

  1. parse it,
  2. extract the authorization code contained in it
  3. and hit Facebook and obtain an access token which will get placed in the request.env['omniauth.auth']['credentials'] hash.

Token Expiry

The expiration time of the access token you obtain will depend on which flow you are using.

Client-Side Flow

If you use the client-side flow, Facebook will give you back a short lived access token (~ 2 hours).

You can exchange this short lived access token for a longer lived version. Read the Facebook docs for more information on exchanging a short lived token for a long lived token.

Server-Side Flow

If you use the server-side flow, Facebook will give you back a longer lived access token (~ 60 days).

Supported Rubies

  • Ruby MRI (2.5, 2.6, 2.7, 3.0)

License

Copyright (c) 2012 by Mark Dodwell

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

omniauth-facebook's People

Contributors

amatsuda avatar blueplanet avatar dlackty avatar donbobka avatar gui avatar mkdynamic avatar mstr03 avatar naudo avatar nchelluri avatar nhosoya avatar okuramasafumi avatar olegkovalenko avatar olivierlacan avatar olleolleolle avatar oriolgual avatar petergoldstein avatar piotrjaworski avatar ryansobol avatar sebastian-stylesaint avatar seivan avatar simi avatar springerigor avatar steverandy avatar swaathi avatar swiknaba avatar tomoya55 avatar tricknotes avatar vesan avatar watsonbox avatar weilu 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  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

omniauth-facebook's Issues

Popup confusion

Hi guys

I'm confused by the purpose of the "popup" option, I have it set yet the FB dialog still takes over the whole window?
I can't see any JS decoration in the code of this gem or Omniauth - do I have to implement the JS myself? Seems what people have done when I Google..

Bit confused as I'm using the out-of-the-box Omniauth config with this FB strategy, following this:

https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

I can see the example code to use FB JS API instead but that seems to conflict with this option.
Any clarification appreciated.

Cheers

Matt

RuntimeError (A refresh_token is not available): with canvas application

Hello!

I tried to implement the canvas application login by redirecting the user to the authentication path with the signed_request as an url parameter when the user enters to my application canvas url. This results with an error message "RuntimeError (A refresh_token is not available):".

Any idea why this is happening?

Facebook - If I use iframe=true, I get nil for env["omniauth.auth"]. :(

Hello

I would like to authorize and use my application only inside the Facebook. Is it possible?

I tried to use this configuration:

    provider :facebook, app_id, app_secret, {:scope => "publish_stream, offline_access, email" , :iframe => true}
    OmniAuth.config.full_host = "http://apps.facebook.com/yourapp/"

But it didn't work. :(

When I try to access the application inside Facebook (iframe) I get nil for env["omniauth.auth"].

If I comment the full_host

    provider :facebook, app_id, app_secret, {:scope => "publish_stream, offline_access, email" , :iframe => true}
    # OmniAuth.config.full_host = "http://apps.facebook.com/yourapp/"

It works very well, but just outside Facebook.

If I remove the iframe parameter

    provider :facebook, app_id, app_secret, {:scope => "publish_stream, offline_access, email"}

I can use the application in both ways, inside and outside the Facebook. But... I can't authorize the application inside the Facebook, just outside. Inside (iframe) I receive the Facebook logo problem. Facebook shows me the logo instead of the auth permissions box.

- iframe = true
    - authorization works inside and outside Facebook 
    - the application opens always outside the Facebook even if I try to access http://apps.facebook.com/yourapp/

- iframe = true (I want to use this one)
    - OmniAuth.config.full_host = "http://apps.facebook.com/yourapp/"
    - I get nil for env["omniauth.auth"]

- iframe = false
    - authorization works ONLY outside Facebook. Inside I receive Facebook logo problem
    - I can access the app inside and outside Facebook

My environment

* omniauth (1.0.0) 
* omniauth-oauth2 (1.0.0) 
* omniauth-facebook (1.0.0.rc1)

Cheers

Short-lived access tokens from signed_request

I have set up a canvas application, with the following initializer:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], :iframe => true
end

OmniAuth.config.full_host = 'http://apps.facebook.com/myapp'

This breaks out of the iframe for authentication, then returns the user to the app inside Facebook, as expected. However, because Facebook sends a signed_request parameter with an access token to canvas apps, this is used instead of completing the OAuth flow with the code from Facebook.

The problem is that as far as I can tell, the access token in the signed request is always short-lived (up to 2 hours), whereas the access token returned from the full server-side OAuth flow has the long-lived expiry (60 days). According to Facebook this will be automatically extended up to once a day when requested.

Has anyone else experienced this issue? I propose to introduce another initialization option, perhaps :always_refresh_access_token, to force a server-side refresh of the access token on authentication.

Access "/oauth/authorize" error

when we use your gem.It turn me to https://graph.facebook.com/oauth/authorize?response_type=code&client_id=234847626576442&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Ffacebook%2Fcallback

and page show bellow error. Can not goto facebook login page.

Fetch Server Info

GET 'https://graph.facebook.com:443/oauth/authorize?response_type=code&client_id=234847626576442&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Ffacebook%2Fcallback'

Return Code: 500

Message: Urlfetch error: ["GET 'https://graph.facebook.com:443/oauth/authorize?response_type=code&client_id=234847626576442&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Ffacebook%2Fcallback' return 400", "GET 'https://graph.facebook.com:443/oauth/authorize?response_type=code&client_id=234847626576442&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Ffacebook%2Fcallback' return 400", "GET 'https://graph.facebook.com:443/oauth/authorize?response_type=code&client_id=234847626576442&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fauth%2Ffacebook%2Fcallback' return 400"]

Facebook not always returning email for user?

I've looked all over the Facebook docs and can't seem to figure out why, even if I require the email permission, I still sometimes get users who are authorized, but do not have email included in the extra hash. Does anyone have any clue how this is possible and how I can absolutely require an email from Facebook?

Gem incompatible with Rails 3.1.6

With this gemfile:

source 'http://rubygems.org'
gem 'rails', '3.1.6'
gem 'omniauth-facebook'

A bundle update results in:

Bundler could not find compatible versions for gem "multi_json":
  In Gemfile:
    rails (= 3.1.6) ruby depends on
      multi_json (< 1.3, >= 1.0) ruby

    omniauth-facebook (>= 0) ruby depends on
      multi_json (1.3.6)

Upgrade to 1.3 now receiving NoAuthorizationCodeError

I recently upgrade to version 1.3 before upgrading to Rails 3.1.5. After upgrading I received this error :

OmniAuth::Strategies::Facebook::NoAuthorizationCodeError: must pass either a code parameter or a signed request (via signed_request parameter or a fbsr_XXX cookie)

Can you confirm this is unrelated to changes between 1.2 and 1.3 ? I looked over the commits and nothing raised my brow.

Has anybody had success using this gem with PhoneGap + Facebook Connect Plugin?

Hey guys,

I've been using OmniAuth-Facebook successfully on my web app.

However, the same server is also serving pages to a PhoneGap app. I started out authenticating successfully with the FB js sdk, with no interaction with the backend.

However, I'm now trying to save the authentication on the backend, and I'm getting an error in the vincinity of the OmniAuth-Facebook or OAuth2 gems.

{"message":"An unknown error has occurred.","type":"OAuthException","code":1}

(The complete ruby inspect is at the end)

Now the FB Connect plugin for PhoneGap is pretty up to date, except that I think it doesn't use OAuth2 yet...

In my FB.login callback, I try to post to "/users/auth/facebook/callback?format=json", my Omniauth callback controller. At this point, the user is successfully authentified on the PhoneGap front-end. But the backend fails to authenticate the user because of that error.

Any hint as to how I could fix or circumvent this would be welcome.

Thanks in advance!

#<OAuth2::Response:0x007fc9941ef900 
  @response=#<Faraday::Response:0x007fc9941ef810 
  @env={:method=>:post, 
        :body=>"{\"error\":{\"message\":\"An unknown error has occurred.\",\"type\":\"OAuthException\",\"code\":1}}",
        :url=>#<Addressable::URI:0x3fe4ca0dc2f0 URI:https://graph.facebook.com/oauth/access_token>,
        :request_headers=>{"Content-Type"=>"application/x-www-form-urlencoded"},
        :parallel_manager=>nil,
        :request=>{:proxy=>nil},
        :ssl=>{},
        :status=>500,
        :response_headers=>{"access-control-allow-origin"=>"*", 
                            "cache-control"=>"no-store",
                            "content-type"=>"text/javascript; charset=UTF-8", 
                            "expires"=>"Sat, 01 Jan 2000 00:00:00 GMT", 
                            "pragma"=>"no-cache", 
                            "www-authenticate"=>"OAuth \"Facebook Platform\" \"unknown_error\" \"An unknown error has occurred.\"", 
                            "x-fb-rev"=>"510648", 
                            "x-fb-debug"=>"WW95nFNcWVopyziu+VJeKnm1aoaSV5A2Wz6eexzkzWA=", 
                            "connection"=>"close", 
                            "date"=>"Thu, 16 Feb 2012 22:05:57 GMT", 
                            "content-length"=>"87"}, 
        :response=>#<Faraday::Response:0x007fc9941ef810 ...>}, 
  @on_complete_callbacks=[]>, 
  @options={:parse=>:query}, 
  @parsed={"{\"error\":{\"message\":\"An unknown error has occurred.\",
              \"type\":\"OAuthException\",\"code\":1}}"=>nil},
  @error=#<OAuth2::Error: OAuth2::Error>>

request.env['omniauth.auth'] seems to sometimes just return the access token.

Every one in a while, this is all I get fromrequest.env['omniauth.auth']:

#<OmniAuth::AuthHash credentials=#<Hashie::Mash expires=false token="...VALID TOKEN FROM FACEBOOK..."> extra=#<Hashie::Mash raw_info="false"> info=#<OmniAuth::AuthHash::InfoHash image="http://graph.facebook.com//picture?type=square"> provider="facebook" uid=nil>

For the most part, all this hash has from my Facebook account is then token. Everything else from (this example](https://github.com/mkdynamic/omniauth-facebook) is missing.

This is happening during a "successful" omniauth transaction. Also, even with the same user, this problem only happens about 1/10 times.

example not working

I was trying to run the example with my app ID and secret, but it failed to load the initial page with the following error:

NoMethodError at /
undefined method `include?' for nil:NilClass
Ruby /Users/ftaher/.rvm/gems/ruby-1.9.2-p290@air/gems/omniauth-1.0.1/lib/omniauth/builder.rb: in call, line 33
Web GET localhost/

I'm using unicorn to run the example.

Can you suggest what I am doing wrong?

Can't get additional permissions.

Hi,

I can't get omniauth to ask Facebook for additional permissions.
Only offline and email are being passed on and asked for.
Here is my initializer code.

Rails.application.config.middleware.use OmniAuth::Builder do

  provider  :facebook,
            'xxx',
            'xxx',
            {
              :client_options => {
                :scope    => 'offline_access,
                              email,
                              manage_notifications,
                              photo_upload,
                              publish_stream,
                              status_update,
                              publish_actions,
                              share_item,
                              video_upload,
                              read_stream,
                              user_about_me
                              user_birthday,
                              user_hometown,
                              user_interests,
                              user_location',
                :display  => 'page',
                :ssl      => {
                  :ca_path => "/etc/ssl/certs"
                }
              }
            }

end

rails 3.1 and omniauth-facebook 1.2.0 not working

when using omniauth-facebook 1.2.0 within a rails 3.1. application - a request for /auth/facebook will result in
error: (as reported also in issue #21)

{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException"
}
}

downgrade to omniauth-facebook 1.1.0 made things working.

"/oauth/authorize": Invalid URL

The URL is : https://graph.facebook.com/oauth/authorize?response_type=code&client_id=...
Response:
The requested URL "/oauth/authorize?r... " , is invalid.

In this page: http://developers.facebook.com/docs/authentication/
the url should be: https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL

Which URL is correct now?

I know there is a similar closed issue, but I tried several versions of omniauth-facebook gem, it does not help. App works with rails 3.1. I can authenticate with LinkedIn, Twitter, but not Facebook.

And when I changed the URL manually, to "https://www.facebook.com/dialog/oauth", I got redirect call from facebook, but I ran into "OpenSSL::SSL::SSLError (hostname was not match with the server certificate)" error.

after upgrading, no longer receiving email

Upgrading from omniauth 0.3 to 1.2.0 and now using omniauth-facebook. I used to receive the user's email address here:

request.env["omniauth.auth"]["user_info"]["email"]

Now i'm getting a hashie back, but request.env["omniauth.auth"].info.email is nil.

I haven't changed any facebook settings with my account, so this tells me the gem is filtering the email for some reason?

Question about callback url

Hi I'm sorry if this isn't the right place but I didn't see a mail list.

I'm allowing my users to log in with with facebook and am using this strategy. I'm having my users fill out a form with their email and password however before creating an account (yes I know, you might say whats the point of using this then, well it's so my users doesn't have to enter all their info in and I can share content with their friend now).

Because my sign up process works like this, I need two call back paths. One path for a use that just wants to sign in, and another for a user creating an account from an invite.

How can I use two of these call backs and point them to my respective controllers?

ie:
match '/auth/:provider/register/callback' => "users#new"
match '/auth/:provider/callback' => "sessions#create"

Thanks and sorry if this isn't the right place to ask.

Enable https:// for 'image' in the Authentication Hash

I have modified the code of the Facebook Strategy class to use https:// or http:// for the URL of the Facebook user image inside the Authentication hash.
I use a new boolean parameter (eg. :secure) passed on provider declaration:

provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], :secure => true

The code of the Facebook Strategy class that I've changed is in this gist: https://gist.github.com/2014580

I hope that you can implement something similar for the next version of the gem, it's useful (IMHO) for websites that use SSL to avoid browser complaints about inclusion of unsafe resources! ;)

Feature request: Set locale or auto-locale

The /me page can be localized with ?locale=de_DE for example. This way things like hometown are sent in the right language, which is very nice for any project that is not confined to English. I suggest you make the locale configurable.

You may also want to provide a :auto setting, that gets and uses the locale of the user:

      def raw_info
        if @raw_info.nil?
          @raw_info = access_token.get('/me').parsed || {}
          @raw_info = access_token.get("/me?locale=#{@raw_info[:locale]}").parsed || {}
        end
        @raw_info
      end

compatibility issue with rails 3.1.5

With this gemfile:

source 'http://rubygems.org'
gem 'rails', '3.1.5'
gem 'omniauth-facebook'

A bundle update results in:

Bundler could not find compatible versions for gem "multi_json":
  In Gemfile:
    rails (= 3.1.5) ruby depends on
      multi_json (< 1.3, >= 1.0) ruby

    omniauth-facebook (>= 0) ruby depends on
      multi_json (1.3.6)

Problem with unicorn+devise+omniauth+omniauth-facebook in Heroku

Hi, I have this controller to deal with omniauth auth:

class AuthenticationsController < ApplicationController
  def create
    omniauth = request.env["omniauth.auth"]
    authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])

  if authentication
    flash[:notice] = "Logged with #{omniauth['provider']}."
    sign_in_and_redirect(:user, authentication.user)
  elsif current_user
    current_user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
    flash[:notice] = "Connected with #{omniauth['provider']}."
    redirect_to edit_user_registration_url
  else
    if session[:active_promocode]
      user = User.new
      user.promo_code_id = session[:active_promocode]
      user.apply_omniauth(omniauth)
      if user.save
        flash[:notice] = "New user with #{omniauth['provider']}."
        sign_in_and_redirect(:user, user)
      else
        session[:omniauth] = omniauth.except('extra')
        redirect_to "#{new_user_registration_url}"
      end
    else
      redirect_to promocode_path
    end
  end
end

def destroy
  @authentication = current_user.authentications.find(params[:id])
  @authentication.destroy
  flash[:notice] = "Logout."
  redirect_to edit_user_registration_url
end
end

The problem is sometimes when two users login in the same time with Facebook, one user get logged in with the account of another user..

Session problem? Omniauth problem? Devise problem?

versions:
devise (2.0.4)
omniauth (1.1.0)
omniauth-facebook (1.2.0)
omniauth-twitter (0.0.10)
unicorn (4.3.0)

facebook auth && secure cookies

So I've run into a conflict with facebook and secure cookies.

I'm currently using AuthLogic, with secure = true, which means the cookie is flagged secure and therefore is only transmitted over a secure connection.

If I enter https://www.mydomain.con (read: that's httpS) as my Site URL in facebook's app config, then I ultimately get an error about having an invalid redirect URL.

My Facebook authentication is therefore not SSL.... So here's what's happening:

  1. User clicks my facebook link, which takes them over to FB where they authenticate
  2. After successful authentication there they are rediected to the not SSL /auth/facebook/callback?blah=whatever
  3. Everything is peachy inside this method, I do a find or create by user, and use AuthLogic's UserSession.create(user, true) to force-create a session.
    -- If I debug out after that statement at the very end of this action there is a session - so AuthLogic has done its job.
  4. The user then gets redirected back to root_url (also not SSL (but it doesn't really matter))
  5. User is not logged in.
  6. Frowny face.

I'm pretty sure the issue is the cookie's secure setting and the fact that /auth/facebook/callback isn't secure, so the client/server refuses to accept the new cookie since it's not a secure connection. Therefore, the next action has no cookie to use to retrive the perfectly valid and created session.

It seems I cannot set my facebook site url to SSL, since FB throws an error on that ( not really sure why - it seems lame that they do this).

Even going always-on-ssl doesn't really solve this, since it seems that the facebook auth method must be non-ssl.

What's a FB hacker to do?

:display param is being ignored in initializer

I've got this in my initializer:

        provider :facebook, Facebook::APP_ID, Facebook::SECRET_KEY, :display => 'popup', :scope => 'email'
end

And yet, the display param gets ignored and it defaults to 'page'. I've even tried 'touch' instead of 'popup'. No dice.

Missing client_id parameter

I'm testing my app in localhost.
When I click on the "login facebook" link from my app, this is the result:

{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException"
}
}

in the URL there isn't the client_id parameter

not receiving extras hash

Hello!
I'm not receiving the extras hash that should come in omniauth.auth:

omniauth.auth   
{"info"=>{"name"=>"my name", "nickname"=>"nickname ok", "first_name"=>"Me", "email"=>"[email protected]"}, "uid"=>"xxxxxx", "provider"=>"facebook"}

This is my configuration:

:facebook, "XXXXXX", "YYYYYY", scope: 'user_birthday,email'

Did I miss anything?

Dynamic providers not working

I'm getting the following exception when trying to implement dynamic providers with Facebook, as described on: https://github.com/intridea/omniauth/wiki/Dynamic-Providers

undefined method `consumer_key=' for <OmniAuth::Strategies::Facebook>

Here is my setup method:

def setup
  if params[:provider] == "facebook"
    site = Site.where(:name => 'whitegallery').first
    request.env['omniauth.strategy'].consumer_key = site.facebook_app_id
    request.env['omniauth.strategy'].consumer_secret = site.facebook_app_secret
  end
  render :text => "Setup complete.", :status => 404
end

I have also tried with client_id and client_secret but simply get an undefined method 'client_key=' instead.

error when I start server

This is the error I get when I try starting the server...

thank you!

/Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/omniauth-1.1.0/lib/omniauth/builder.rb:38:in rescue in provider': Could not find matching strategy for :facebook. You may need to install an additional gem (such as omniauth-facebook). (LoadError) from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/omniauth-1.1.0/lib/omniauth/builder.rb:35:inprovider'
from /Users/aa/rails_projects/facebook-invitations-demo/config/initializers/omniauth.rb:3:in block in <top (required)>' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/builder.rb:46:ininstance_eval'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/builder.rb:46:in initialize' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/omniauth-1.1.0/lib/omniauth/builder.rb:10:ininitialize'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:33:in new' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:33:inbuild'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:in block in build' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:ineach'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:in inject' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:inbuild'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/application.rb:162:in app' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/application/finisher.rb:35:inblock in module:Finisher'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/initializable.rb:25:in instance_exec' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/initializable.rb:25:inrun'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/initializable.rb:50:in block in run_initializers' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/initializable.rb:49:ineach'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/initializable.rb:49:in run_initializers' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/application.rb:134:ininitialize!'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/application.rb:77:in method_missing' from /Users/aa/rails_projects/facebook-invitations-demo/config/environment.rb:5:in<top (required)>'
from /Users/aa/rails_projects/facebook-invitations-demo/config.ru:3:in require' from /Users/aa/rails_projects/facebook-invitations-demo/config.ru:3:inblock in

'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/builder.rb:46:in instance_eval' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/builder.rb:46:ininitialize'
from /Users/aa/rails_projects/facebook-invitations-demo/config.ru:1:in new' from /Users/aa/rails_projects/facebook-invitations-demo/config.ru:1:in'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/builder.rb:35:in eval' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/builder.rb:35:inparse_file'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/server.rb:162:in app' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/server.rb:253:inwrapped_app'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/rack-1.2.5/lib/rack/server.rb:204:in start' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/commands/server.rb:65:instart'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/commands.rb:30:in block in <top (required)>' from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/commands.rb:27:intap'
from /Users/aa/.rvm/gems/ruby-1.9.2-p318@fb-demo1/gems/railties-3.0.9/lib/rails/commands.rb:27:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `'

Here are my gems...

[facebook-invitations-demo (master)]$ bundle
Using rake (0.9.2.2)
Using abstract (1.0.0)
Using activesupport (3.0.9)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.9)
Using erubis (2.6.6)
Using rack (1.2.5)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.33)
Using actionpack (3.0.9)
Using mime-types (1.18)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.2.19)
Using actionmailer (3.0.9)
Using arel (2.0.10)
Using activerecord (3.0.9)
Using activeresource (3.0.9)
Using daemons (1.0.10)
Using multipart-post (1.1.5)
Using faraday (0.8.1)
Using gem_plugin (0.2.3)
Using hashie (1.2.0)
Using json (1.7.3)
Using rdoc (3.12)
Using thor (0.14.6)
Using railties (3.0.9)
Using jquery-rails (1.0.19)
Using multi_json (1.3.6)
Using koala (1.5.0)
Using mongrel (1.2.0.pre2)
Using omniauth (1.1.0)
Using bundler (1.1.3)
Using rails (3.0.9)
Using sqlite3 (1.3.6)
Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed.

Facebook Canvas issues?

I'm having trouble authenticating within Facebook's canvas... currently, I detect for the signed request like so:

def signed_facebook_request?
    if params[:signed_request]
      session[:canvas] = true
      fb_data = parse_signed_request(FB_CONFIG['secret'], params[:signed_request])
      uid = fb_data['user_id']
      unless @auth = Authorization.find_by_provider_and_uid('facebook', uid)
        redirect_to "/auth/facebook/callback?code=#{fb_data['oauth_token']}"
      else
        self.current_user = @auth.user
      end
    end
  end

But, I get an invalid credentials response ... I thought, looking through the code, the callback would take the oauth token from the signed request and go from there, but is that not the case? Or am I doing something clearly wrong in the redirect?

Feature request: User application deletion

I couldn't find any documentation on how to do this using this gem, but it would be nice to be able to remove the original application added through this gem from the facebook user's application list.

BirthDate

Hello,
is there a way to obtain additional info about the user, for example his birthdate ?

urls[ 'website' ] is not populated

For some reasons I don't see the website key populated in the raw_info hash, with the result that I'm not able to get a user's personal website even if it's available on Facebook (i.e. urls=#<Hashie::Mash Facebook="http://www.facebook.com/nwieland">>).

Is it happening only to me? How can I double check / debug this? If I look at Facebook the website is correctly inserted.

Per-request scope being ignored

I am attempting to use the per-request scope described on the main page so I can ask for extended permissions for some users/features. As an example, I redirect the user to a URL such as "/auth/facebook?scope=email" (dropping the default offline_access perm). The user is actually redirected to:

https://www.facebook.com/dialog/permissions.request?app_id=[snip]&display=page&next=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fcallback&response_type=code&perms=email%2Coffline_access&fbconnect=1

My app is configured to use Facebook's Enhanced Auth Dialog. You can see at the end of the URL 'offline_access' is still in the request. No matter what I put in scope it is always "perms=email%2Coffline_access" which are the defaults.

My configuration is very plain vanilla:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, my_api_key, my_secret_key
end

Relevant gem versions:

omniauth (1.0.2)
  hashie (~> 1.2)
  rack
omniauth-facebook (1.2.0)
  omniauth-oauth2 (~> 1.0.0)
omniauth-oauth2 (1.0.0)
  oauth2 (~> 0.5.0)
  omniauth (~> 1.0)

Issue with omniauth-facebook

Using omniauth-facebook in my Rails app raises this issue. How do I fix this?
{
"error": {
"message": "Missing client_id parameter.",
"type": "OAuthException",
"code": 101
}
}

NoAuthorizationCodeError thrown when people visit us from Facebook

On developers.facebook.com we've set the sign-in callback url to "https://oursite.com/auth/facebook/callback", and that's worked great for using Facebook to sign in. However, whenever someone finds our app on Facebook, and clicks to visit us, Facebook uses that same url to send people to our site. So people arrive at our site via a GET with no parameters, and our app raises OmniAuth::Strategies::Facebook::NoAuthorizationCodeError (see below).

Would it be okay to patch omniauth-facebook that so it only raised an exception on POST?

  • Daniel

A OmniAuth::Strategies::Facebook::NoAuthorizationCodeError occurred in #:

must pass either a code parameter or a signed request (via signed_request parameter or a fbsr_XXX cookie)
omniauth-facebook (1.3.0) lib/omniauth/strategies/facebook.rb:179:in `with_authorization_code!'

Delay when processing callback in production

When I use omniauth facebook login in dev it works great fast and snappy. However, as soon as deploy to production running on Ubuntu and Nginx the callback takes forever to process. It works but takes a LONG time when I turn on debugging in rails 3.2.1 prod log it hangs here forever:

Started GET "/users/auth/facebook/callback?code=xxx" for 127.0.0.1 at 2012-03-01 21:50:48 -0800
Processing by Users::OmniauthCallbacksController#facebook as HTML

then after 1-5 seconds it process as normal. Only in production mode on Nginx. Any tips or suggestions where to look? It works just the login delay is too much. Rails 3.2.1, Nginx, Postgres, Devise 2, Omni 1.0.2, omni-fb 1.2

Redirect URL getting rendered to window instead of followed

When I hit /auth/facebook, the browser isn't bouncing over to Facebook. Instead, the location bar still reads http://localhost:3000/auth/facebook, and there is text in the browser window reading "Redirecting to https://graph.facebook.com/oauth/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A3000[... etc.]"

Other strategies are working fine.

I'm worried that this is some trivial issue, but a whole lot of searches aren't turning up any common causes for redirects to get treated this way. Any help is appreciated.

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.