Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Support server_state parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
milk1000cc committed Jan 16, 2017
1 parent a77a841 commit 99df357
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/omniauth/strategies/mixi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ def authorize_params
params[:scope] = BASIC_SCOPE
end
end
params[:server_state] = get_server_state
session['omniauth.server_state'] = params[:server_state]
end
end

def token_params
super.merge(:server_state => session.delete('omniauth.server_state'))
end

private

def prune!(hash)
Expand Down Expand Up @@ -108,6 +114,20 @@ def location
end
prefecture
end

def get_server_state
opts = {
:body => {
'grant_type' => 'server_state',
'client_id' => options.client_id
},
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:raise_errors => true,
:parse => true
}
response = client.request(:post, options.client_options.token_url, opts)
response.parsed['server_state']
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/omniauth/strategies/mixi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
target = OmniAuth::Strategies::Mixi.new(nil, *args).tap do |strategy|
strategy.stub!(:request).and_return(request)
strategy.stub!(:session).and_return({})
strategy.stub!(:get_server_state)
end
target.authorize_params[:scope].should == 'r_profile'
end
Expand All @@ -44,6 +45,7 @@
target = OmniAuth::Strategies::Mixi.new(nil, *args).tap do |strategy|
strategy.stub!(:request).and_return(request)
strategy.stub!(:session).and_return({})
strategy.stub!(:get_server_state)
end
target.authorize_params[:scope].should ==
'r_profile r_profile_name r_profile_location r_profile_about_me'
Expand All @@ -56,6 +58,7 @@
target = OmniAuth::Strategies::Mixi.new(nil, *args).tap do |strategy|
strategy.stub!(:request).and_return(request)
strategy.stub!(:session).and_return({})
strategy.stub!(:get_server_state)
end
target.authorize_params[:scope].should == 'r_profile r_voice'
end
Expand All @@ -67,6 +70,7 @@
target = OmniAuth::Strategies::Mixi.new(nil, *args).tap do |strategy|
strategy.stub!(:request).and_return(request)
strategy.stub!(:session).and_return({})
strategy.stub!(:get_server_state)
end
target.authorize_params[:display].should == 'touch'
end
Expand All @@ -78,9 +82,32 @@
target = OmniAuth::Strategies::Mixi.new(nil, *args).tap do |strategy|
strategy.stub!(:request).and_return(request)
strategy.stub!(:session).and_return({})
strategy.stub!(:get_server_state)
end
target.authorize_params[:display].should == 'touch'
end

it 'should include the server_state parameter' do
request = stub('Request')
request.stub!(:params).and_return({})
target = subject.tap do |strategy|
strategy.stub!(:request).and_return(request)
strategy.stub!(:session).and_return({})
strategy.stub!(:get_server_state).and_return('serverState1')
end
target.authorize_params[:server_state].should == 'serverState1'
target.session['omniauth.server_state'].should == 'serverState1'
end
end

describe 'Token params' do
it 'should include the server_state parameter' do
target = subject.tap do |strategy|
strategy.stub!(:session).
and_return('omniauth.server_state' => 'serverState1')
end
target.token_params['server_state'].should == 'serverState1'
end
end

describe 'User info' do
Expand Down

0 comments on commit 99df357

Please sign in to comment.