Skip to content

OAuth2 Strategy for Facebook Long-Lived User Access Tokens

License

Notifications You must be signed in to change notification settings

fdeschenes/oauth2-fb-exchange-token-strategy

Repository files navigation

OAuth2 Strategy for Facebook Long-Lived User Access Tokens

Gem Version Coverage Status Maintainability License: 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.

This gem adds a new strategy to the excellent 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

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