Codebase list ruby-omniauth-facebook / 0106bb4
initial implementation for facebook strategy Mark Dodwell 12 years ago
4 changed file(s) with 101 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
22 module OmniAuth
33 module Strategies
44 class Facebook < OmniAuth::Strategies::OAuth2
5 include OmniAuth::Strategy
5 option :client_options, {
6 :site => 'https://graph.facebook.com',
7 :token_url => '/oauth/access_token'
8 }
9
10 option :token_params, {
11 :parse => :query
12 }
13
14 option :access_token_options, {
15 :header_format => 'OAuth %s',
16 :param_name => 'access_token'
17 }
18
19 def build_access_token
20 super.tap do |token|
21 token.options.merge!(access_token_options)
22 end
23 end
24
25 def access_token_options
26 options.access_token_options.inject({}) { |h,(k,v)| h[k.to_sym] = v; h }
27 end
628 end
729 end
830 end
11 require 'omniauth-facebook'
22
33 describe OmniAuth::Strategies::Facebook do
4 subject do
5 OmniAuth::Strategies::Facebook.new(nil, @options || {})
6 end
7
8 it_should_behave_like 'an oauth2 strategy'
9
10 describe '#client' do
11 it 'has correct Facebook site' do
12 subject.client.site.should eq('https://graph.facebook.com')
13 end
14
15 it 'has correct authorize url' do
16 subject.client.options[:authorize_url].should eq('/oauth/authorize')
17 end
18
19 it 'has correct token url' do
20 subject.client.options[:token_url].should eq('/oauth/access_token')
21 end
22 end
23
24 describe '#authorize_params' do
25 it 'is empty by default' do
26 subject.authorize_params.should be_empty
27 end
28 end
29
30 describe '#token_params' do
31 it 'has correct parse strategy' do
32 subject.token_params[:parse].should eq(:query)
33 end
34 end
35
36 describe '#access_token_options' do
37 it 'has correct param name by default' do
38 subject.access_token_options[:param_name].should eq('access_token')
39 end
40
41 it 'has correct header format by default' do
42 subject.access_token_options[:header_format].should eq('OAuth %s')
43 end
44 end
445 end
00 require 'bundler/setup'
11 require 'rspec'
2 Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
23
34 RSpec.configure do |config|
45 end
0 shared_examples 'an oauth2 strategy' do
1 describe '#client' do
2 it 'should be initialized with symbolized client_options' do
3 @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
4 subject.client.options[:authorize_url].should == 'https://example.com'
5 end
6 end
7
8 describe '#authorize_params' do
9 it 'should include any authorize params passed in the :authorize_params option' do
10 @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
11 subject.authorize_params['foo'].should eq('bar')
12 subject.authorize_params['baz'].should eq('zip')
13 end
14
15 it 'should include top-level options that are marked as :authorize_options' do
16 @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
17 subject.authorize_params['scope'].should eq('bar')
18 subject.authorize_params['foo'].should eq('baz')
19 end
20 end
21
22 describe '#token_params' do
23 it 'should include any authorize params passed in the :authorize_params option' do
24 @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
25 subject.token_params['foo'].should eq('bar')
26 subject.token_params['baz'].should eq('zip')
27 end
28
29 it 'should include top-level options that are marked as :authorize_options' do
30 @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
31 subject.token_params['scope'].should eq('bar')
32 subject.token_params['foo'].should eq('baz')
33 end
34 end
35 end