https://github.com/simi/omniauth-facebook
Facebook OAuth2 Strategy for OmniAuth
https://github.com/simi/omniauth-facebook
Keywords from Contributors
activerecord mvc activejob rubygem rack oauth2 omniauth sinatra crash-reporting rspec
Last synced: about 21 hours ago
JSON representation
Repository metadata
Facebook OAuth2 Strategy for OmniAuth
- Host: GitHub
- URL: https://github.com/simi/omniauth-facebook
- Owner: simi
- Created: 2011-10-15T07:37:00.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2025-07-17T22:05:00.000Z (5 months ago)
- Last Synced: 2025-12-10T13:35:30.428Z (14 days ago)
- Language: Ruby
- Homepage: https://simi.github.io/omniauth-facebook/
- Size: 357 KB
- Stars: 1,267
- Watchers: 32
- Forks: 403
- Open Issues: 2
- Releases: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
README.md
OmniAuth Facebook

📣 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 |
config_id |
The configuration ID to use for a System User access token with Facebook Login for Business. Read the Facebook docs for more details: https://developers.facebook.com/docs/facebook-login/facebook-login-for-business#invoke-a--login-dialog | |
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 v19.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 v20.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/v20.0',
authorize_url: "https://www.facebook.com/v20.0/dialog/oauth"
}
end
Per-Request Options
If you want to set the display format, auth_type, scope or config_id on a per-request basis, you can just pass it to the OmniAuth request phase URL, for example: /auth/facebook?display=popup, /auth/facebook?scope=email or /auth/facebook?config_id=001.
Auth Hash
Here's an example Auth Hash available in request.env['omniauth.auth']:
{
provider: 'facebook',
uid: '1234567',
info: {
email: 'joe@bloggs.com',
name: 'Joe Bloggs',
first_name: 'Joe',
last_name: 'Bloggs',
image: 'http://graph.facebook.com/1234567/picture?type=square',
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: 'joe@bloggs.com',
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:
- parse it,
- extract the authorization code contained in it
- 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 (3.0, 3.1, 3.2 and 3.3)
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.
Owner metadata
- Name: Josef Šimánek
- Login: simi
- Email:
- Kind: user
- Description: I'm just a poor boy, I need no sympathy. But I'm just a poor boy and nobody loves me. He's just a poor boy from a poor family.
- Website: http://twitter.com/retrorubies
- Location: Prague, Czech republic
- Twitter:
- Company: self - deli clerk
- Icon url: https://avatars.githubusercontent.com/u/193936?u=0009ccae9daa72c7b1c8590f9c67560b29a54902&v=4
- Repositories: 312
- Last ynced at: 2023-04-09T06:36:36.029Z
- Profile URL: https://github.com/simi
GitHub Events
Total
- Issues event: 2
- Watch event: 12
- Issue comment event: 8
- Push event: 4
- Pull request review event: 1
- Pull request event: 12
- Fork event: 4
Last Year
- Issues event: 2
- Watch event: 9
- Issue comment event: 8
- Push event: 4
- Pull request review event: 1
- Pull request event: 7
- Fork event: 2
Committers metadata
Last synced: 2 days ago
Total Commits: 306
Total Committers: 64
Avg Commits per committer: 4.781
Development Distribution Score (DDS): 0.474
Commits in past year: 4
Committers in past year: 3
Avg Commits per committer in past year: 1.333
Development Distribution Score (DDS) in past year: 0.5
| Name | Commits | |
|---|---|---|
| Mark Dodwell | m****k@m****k | 161 |
| Josef Šimánek | j****k@g****m | 47 |
| frausto | n****o@f****m | 5 |
| Fabian Winkler | w****g@h****e | 5 |
| Wei Lu | l****e@g****m | 5 |
| Akira Matsuda | r****e@d****p | 5 |
| Olle Jonsson | o****n@g****m | 4 |
| Howard Wilson | h****d@w****t | 4 |
| Steve Randy Tantra | s****y@g****m | 2 |
| Ryunosuke SATO | t****s@g****m | 2 |
| Ryan Sobol | c****t@r****m | 2 |
| Richard Lee | d****y@g****m | 2 |
| Piotr Jaworski | p****w@g****m | 2 |
| Lud | s****a | 2 |
| Igor Springer | s****r@g****m | 2 |
| David Milanese | a****d | 2 |
| Peter Goldstein | p****n@g****m | 2 |
| Amos Elliston | a****s@g****m | 2 |
| Mark Dodwell | a****s@m****k | 2 |
| Wes Gamble | w****s@r****m | 2 |
| Vesa Vänskä | v****0@g****m | 2 |
| blueplanet | e****e@g****m | 2 |
| GermanDZ | g****m@n****r | 1 |
| Gady | g****y@o****l | 1 |
| Fran | f****s@g****m | 1 |
| Brian Landau | b****u@g****m | 1 |
| Brendan Loudermilk | b****n@g****m | 1 |
| Leandro Tk | l****k@h****m | 1 |
| Michal Szyndel | m****z@s****m | 1 |
| Niels Richter | n****s@e****e | 1 |
| and 34 more... | ||
Committer domains:
- mkdynamic.co.uk: 2
- fitstar.com: 1
- handgemen.ge: 1
- dio.jp: 1
- watsonbox.net: 1
- ryansobol.com: 1
- geni.com: 1
- redflag.com: 1
- ndz.com.ar: 1
- opinya.co.il: 1
- gophilosophie.com: 1
- sent.com: 1
- endil.de: 1
- cookpad.com: 1
- stylesaint.com: 1
- olivierlacan.com: 1
- naudo.de: 1
- cadenza-tech.com: 1
- futurelearn.com: 1
- suse.de: 1
- shift1.nl: 1
- nevir.net: 1
- bitdeli.com: 1
Issue and Pull Request metadata
Last synced: about 2 months ago
Total issues: 62
Total pull requests: 59
Average time to close issues: about 1 year
Average time to close pull requests: 8 months
Total issue authors: 58
Total pull request authors: 39
Average comments per issue: 5.02
Average comments per pull request: 4.1
Merged pull request: 29
Bot issues: 0
Bot pull requests: 0
Past year issues: 1
Past year pull requests: 3
Past year average time to close issues: N/A
Past year average time to close pull requests: about 4 hours
Past year issue authors: 1
Past year pull request authors: 2
Past year average comments per issue: 0.0
Past year average comments per pull request: 0.33
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- olleolleolle (3)
- mr3abd (2)
- Lee1984 (2)
- dcalixto (1)
- swiknaba (1)
- joker-777 (1)
- fbukevin (1)
- crystalneth (1)
- jbaugh (1)
- andrewhavens (1)
- madeleinel (1)
- jivKrishna (1)
- matthewtusker (1)
- arslanyousaf77 (1)
- mradzwilla (1)
Top Pull Request Authors
- olleolleolle (4)
- aussiDavid (4)
- wynksaiddestroy (4)
- simi (3)
- niels (3)
- Rubyist007 (2)
- harism2 (2)
- enewbury (2)
- springerigor (2)
- koshilife (2)
- swiknaba (2)
- Lillibugg101 (2)
- anklos (1)
- khiav223577 (1)
- nhosoya (1)
Top Issue Labels
- no-issue-activity (35)
- patches-welcome (2)
Top Pull Request Labels
- no-pr-activity (28)
- pinned (2)
Package metadata
- Total packages: 2
-
Total downloads:
- rubygems: 127,454,432 total
- Total docker downloads: 1,153,506,032
- Total dependent packages: 62 (may contain duplicates)
- Total dependent repositories: 26,006 (may contain duplicates)
- Total versions: 48
- Total maintainers: 1
- Total advisories: 2
gem.coop: omniauth-facebook
Facebook OAuth2 Strategy for OmniAuth
- Homepage: https://github.com/simi/omniauth-facebook
- Documentation: http://www.rubydoc.info/gems/omniauth-facebook/
- Licenses: MIT
- Latest release: 10.0.0 (published over 1 year ago)
- Last Synced: 2025-12-22T07:49:08.963Z (2 days ago)
- Versions: 24
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 63,729,353 Total
- Docker Downloads: 576,753,016
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.143%
- Downloads: 0.429%
- Maintainers (1)
rubygems.org: omniauth-facebook
Facebook OAuth2 Strategy for OmniAuth
- Homepage: https://github.com/simi/omniauth-facebook
- Documentation: http://www.rubydoc.info/gems/omniauth-facebook/
- Licenses: MIT
- Latest release: 10.0.0 (published over 1 year ago)
- Last Synced: 2025-12-21T07:52:00.478Z (3 days ago)
- Versions: 24
- Dependent Packages: 62
- Dependent Repositories: 26,006
- Downloads: 63,725,079 Total
- Docker Downloads: 576,753,016
-
Rankings:
- Docker downloads count: 0.214%
- Dependent repos count: 0.221%
- Downloads: 0.374%
- Dependent packages count: 0.449%
- Average: 0.714%
- Forks count: 1.311%
- Stargazers count: 1.717%
- Maintainers (1)
- Advisories:
Dependencies
- omniauth-facebook >= 0
- sinatra >= 0
- sinatra-reloader >= 0
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
- actions/stale v1 composite
- rack >= 2.0
- backports 3.15.0
- faraday 1.1.0
- hashie 4.1.0
- jwt 2.2.2
- multi_json 1.14.1
- multi_xml 0.6.0
- multipart-post 2.1.1
- mustermann 1.1.1
- oauth2 1.4.4
- omniauth 1.9.1
- omniauth-facebook 8.0.0
- omniauth-oauth2 1.7.0
- rack 2.2.3
- rack-protection 2.0.8.1
- ruby2_keywords 0.0.2
- sinatra 2.0.8.1
- sinatra-contrib 2.0.8.1
- sinatra-reloader 1.0
- tilt 2.0.10
- minitest >= 0 development
- mocha >= 0 development
- rake >= 0 development
- omniauth-oauth2 ~> 1.2
Score: 32.27576427427167