mirror of
https://github.com/simi/omniauth-facebook.git
synced 2022-11-09 12:32:45 -05:00
initial implementation for facebook strategy
This commit is contained in:
parent
ec513d5012
commit
0106bb4b15
4 changed files with 101 additions and 1 deletions
|
@ -3,7 +3,29 @@ require 'omniauth/strategies/oauth2'
|
|||
module OmniAuth
|
||||
module Strategies
|
||||
class Facebook < OmniAuth::Strategies::OAuth2
|
||||
include OmniAuth::Strategy
|
||||
option :client_options, {
|
||||
:site => 'https://graph.facebook.com',
|
||||
:token_url => '/oauth/access_token'
|
||||
}
|
||||
|
||||
option :token_params, {
|
||||
:parse => :query
|
||||
}
|
||||
|
||||
option :access_token_options, {
|
||||
:header_format => 'OAuth %s',
|
||||
:param_name => 'access_token'
|
||||
}
|
||||
|
||||
def build_access_token
|
||||
super.tap do |token|
|
||||
token.options.merge!(access_token_options)
|
||||
end
|
||||
end
|
||||
|
||||
def access_token_options
|
||||
options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,4 +2,45 @@ require 'spec_helper'
|
|||
require 'omniauth-facebook'
|
||||
|
||||
describe OmniAuth::Strategies::Facebook do
|
||||
subject do
|
||||
OmniAuth::Strategies::Facebook.new(nil, @options || {})
|
||||
end
|
||||
|
||||
it_should_behave_like 'an oauth2 strategy'
|
||||
|
||||
describe '#client' do
|
||||
it 'has correct Facebook site' do
|
||||
subject.client.site.should eq('https://graph.facebook.com')
|
||||
end
|
||||
|
||||
it 'has correct authorize url' do
|
||||
subject.client.options[:authorize_url].should eq('/oauth/authorize')
|
||||
end
|
||||
|
||||
it 'has correct token url' do
|
||||
subject.client.options[:token_url].should eq('/oauth/access_token')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#authorize_params' do
|
||||
it 'is empty by default' do
|
||||
subject.authorize_params.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#token_params' do
|
||||
it 'has correct parse strategy' do
|
||||
subject.token_params[:parse].should eq(:query)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#access_token_options' do
|
||||
it 'has correct param name by default' do
|
||||
subject.access_token_options[:param_name].should eq('access_token')
|
||||
end
|
||||
|
||||
it 'has correct header format by default' do
|
||||
subject.access_token_options[:header_format].should eq('OAuth %s')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'bundler/setup'
|
||||
require 'rspec'
|
||||
Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
|
||||
|
||||
RSpec.configure do |config|
|
||||
end
|
||||
|
|
36
spec/support/shared_examples.rb
Normal file
36
spec/support/shared_examples.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
shared_examples 'an oauth2 strategy' do
|
||||
describe '#client' do
|
||||
it 'should be initialized with symbolized client_options' do
|
||||
@options = { :client_options => { 'authorize_url' => 'https://example.com' } }
|
||||
subject.client.options[:authorize_url].should == 'https://example.com'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#authorize_params' do
|
||||
it 'should include any authorize params passed in the :authorize_params option' do
|
||||
@options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
|
||||
subject.authorize_params['foo'].should eq('bar')
|
||||
subject.authorize_params['baz'].should eq('zip')
|
||||
end
|
||||
|
||||
it 'should include top-level options that are marked as :authorize_options' do
|
||||
@options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
||||
subject.authorize_params['scope'].should eq('bar')
|
||||
subject.authorize_params['foo'].should eq('baz')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#token_params' do
|
||||
it 'should include any authorize params passed in the :authorize_params option' do
|
||||
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
|
||||
subject.token_params['foo'].should eq('bar')
|
||||
subject.token_params['baz'].should eq('zip')
|
||||
end
|
||||
|
||||
it 'should include top-level options that are marked as :authorize_options' do
|
||||
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
||||
subject.token_params['scope'].should eq('bar')
|
||||
subject.token_params['foo'].should eq('baz')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue