Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pass custom state param #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/omniauth/amazon/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module Amazon
VERSION = "1.0.1"
VERSION = "1.1.0"
end
end
21 changes: 21 additions & 0 deletions lib/omniauth/strategies/amazon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ def build_access_token
client.auth_code.get_token(verifier, token_params)
end

def query_string
super.gsub(/\?state=[^&]*&?/, '')
end

def authorize_params
options.authorize_params[:state] = state
params = options.authorize_params.merge(options_for("authorize"))
if OmniAuth.config.test_mode
@env ||= {}
@env["rack.session"] ||= {}
end
session["omniauth.state"] = params[:state]
params
end

uid { raw_info['Profile']['CustomerId'] }

info do
Expand Down Expand Up @@ -57,6 +72,12 @@ def raw_info
params = {:params => { :access_token => access_token.token}}
@raw_info ||= access_token.client.request(:get, url, params).parsed
end

private

def state
request.params["state"] || SecureRandom.hex(24)
end
end
end
end
8 changes: 4 additions & 4 deletions omniauth-amazon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require 'omniauth/amazon/version'
Gem::Specification.new do |spec|
spec.name = "omniauth-amazon"
spec.version = OmniAuth::Amazon::VERSION
spec.authors = ["Stafford Brunk"]
spec.email = ["[email protected]"]
spec.authors = ["Stafford Brunk", "Lenart Rudel"]
spec.email = ["[email protected]", "[email protected]"]
spec.description = %q{Login with Amazon OAuth2 strategy for OmniAuth 1.0}
spec.summary = %q{Login with Amazon OAuth2 strategy for OmniAuth 1.0}
spec.homepage = "https://github.com/wingrunr21/omniauth-amazon"
Expand All @@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
spec.add_dependency 'omniauth', '~> 1.0'
spec.add_dependency 'omniauth-oauth2', '~> 1.1'

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency 'rspec', '~> 2.13'
spec.add_development_dependency 'rspec', '>= 2.13'
spec.add_development_dependency 'rack-test'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'webmock'
Expand Down
6 changes: 6 additions & 0 deletions spec/omniauth/strategies/amazon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
expect(subject.callback_path).to eq('/auth/amazon/callback')
end
end

describe '#scope' do
it 'passes custom state to Amazon site'
it 'generates random state value when one is not explicitly provided'
it 'strips state from callback_url query params'
end
end