https://github.com/fdeschenes/oauth2-fb-exchange-token-strategy
OAuth2 Strategy for Facebook Long-Lived User Access Tokens
https://github.com/fdeschenes/oauth2-fb-exchange-token-strategy
facebook facebook-graph-api facebook-graph-api-login oauth2 oauth2-strategy ruby
Last synced: over 1 year ago
JSON representation
OAuth2 Strategy for Facebook Long-Lived User Access Tokens
- Host: GitHub
- URL: https://github.com/fdeschenes/oauth2-fb-exchange-token-strategy
- Owner: fdeschenes
- License: mit
- Created: 2020-11-14T14:19:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-14T00:37:31.000Z (over 2 years ago)
- Last Synced: 2025-04-08T14:17:06.731Z (over 1 year ago)
- Topics: facebook, facebook-graph-api, facebook-graph-api-login, oauth2, oauth2-strategy, ruby
- Language: Ruby
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# OAuth2 Strategy for Facebook Long-Lived User Access Tokens
[](https://badge.fury.io/rb/oauth2_fb_exchange_token_strategy)
[](https://coveralls.io/github/fdeschenes/oauth2-fb-exchange-token-strategy?branch=master)
[](https://codeclimate.com/github/fdeschenes/oauth2-fb-exchange-token-strategy/maintainability)
[](https://opensource.org/licenses/MIT)
As per Facebook, default User and Page access tokens are short-lived, expiring in hours, however, you can [exchange a short-lived token for a long-lived token](https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing/).
This gem adds a new strategy to the excellent [oauth2](https://github.com/oauth-xx/oauth2) gem that can be used to do just that.
## Installation
```
gem install oauth2_fb_exchange_token_strategy
```
Or inside Gemfile
```
gem 'oauth2_fb_exchange_token_strategy'
```
## Usage Examples
```ruby
require 'oauth2'
require 'oauth2_fb_exchange_token_strategy'
client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://graph.facebook.com/v9.0', authorize_url: 'https://www.facebook.com/v8.0/dialog/oauth', token_url: 'oauth/access_token')
short_lived_token = client.auth_code.get_token('authorization_code_value', redirect_uri: 'http://example.org/oauth2/callback')
token = client.fb_exchange_token.get_token(short_lived_token.token)
# => OAuth2::AccessToken
```