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

Support ruby-jwt 2.0 #93

Merged
merged 2 commits into from
Oct 4, 2017
Merged
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rvm:
- 2.2.5
- 2.1
- 2.0.0
- jruby-9000
- jruby-9.1.9.0
script: "rake spec:all"
before_install:
- sudo apt-get update
Expand Down
1 change: 1 addition & 0 deletions lib/signet/oauth_2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ def id_token=(new_id_token)
#
# @return [String] The decoded ID token.
def decoded_id_token(public_key=nil, options = {})
options[:algorithm] ||= signing_algorithm
payload, _header = JWT.decode(self.id_token, public_key, !!public_key, options)
if !payload.has_key?('aud')
raise Signet::UnsafeOperationError, 'No ID token audience declared.'
Expand Down
2 changes: 1 addition & 1 deletion signet.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'addressable', '~> 2.3'
s.add_runtime_dependency 'faraday', '~> 0.9'
s.add_runtime_dependency 'multi_json', '~> 1.10'
s.add_runtime_dependency 'jwt', '~> 1.5'
s.add_runtime_dependency 'jwt', '>= 1.5', '< 3.0'

s.add_development_dependency 'rake', '~> 10.0'
s.add_development_dependency 'yard', '~> 0.8'
Expand Down
12 changes: 6 additions & 6 deletions spec/signet/oauth_2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def build_form_encoded_response(payload)
jwt = @client.to_jwt
expect(jwt).not_to be_nil

claim, header = JWT.decode(jwt, @key.public_key, true)
claim, header = JWT.decode(jwt, @key.public_key, true, algorithm: 'RS256')
expect(claim["iss"]).to eq '[email protected]'
expect(claim["scope"]).to eq 'https://www.googleapis.com/auth/userinfo.profile'
expect(claim["aud"]).to eq 'https://accounts.google.com/o/oauth2/token'
Expand All @@ -210,7 +210,7 @@ def build_form_encoded_response(payload)
jwt = @client.to_jwt
expect(jwt).not_to be_nil

claim, header = JWT.decode(jwt, @key.public_key, true)
claim, header = JWT.decode(jwt, @key.public_key, true, algorithm: 'RS256')
expect(claim["iss"]).to eq '[email protected]'
expect(claim["prn"]).to eq '[email protected]'
expect(claim["scope"]).to eq 'https://www.googleapis.com/auth/userinfo.profile'
Expand All @@ -222,7 +222,7 @@ def build_form_encoded_response(payload)
jwt = @client.to_jwt
expect(jwt).not_to be_nil

claim, header = JWT.decode(jwt, @key.public_key, true)
claim, header = JWT.decode(jwt, @key.public_key, true, algorithm: 'RS256')
expect(claim["iss"]).to eq '[email protected]'
expect(claim["prn"]).to eq '[email protected]'
expect(claim["scope"]).to eq 'https://www.googleapis.com/auth/userinfo.profile'
Expand All @@ -234,7 +234,7 @@ def build_form_encoded_response(payload)
jwt = @client.to_jwt
expect(jwt).not_to be_nil

claim, header = JWT.decode(jwt, @key.public_key, true)
claim, header = JWT.decode(jwt, @key.public_key, true, algorithm: 'RS256')
expect(claim["iss"]).to eq '[email protected]'
expect(claim["sub"]).to eq '[email protected]'
expect(claim["scope"]).to eq 'https://www.googleapis.com/auth/userinfo.profile'
Expand All @@ -258,7 +258,7 @@ def build_form_encoded_response(payload)
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
stub.post('/o/oauth2/token') do |env|
params = Addressable::URI.form_unencode(env[:body])
claim, header = JWT.decode(params.assoc("assertion").last, @key.public_key)
claim, header = JWT.decode(params.assoc("assertion").last, @key.public_key, true, algorithm: 'RS256')
expect(params.assoc("grant_type")).to eq ['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer']
build_json_response({
"access_token" => "1/abcdef1234567890",
Expand Down Expand Up @@ -294,7 +294,7 @@ def build_form_encoded_response(payload)
jwt = @client.to_jwt
expect(jwt).not_to be_nil

claim, header = JWT.decode(jwt, @key, true)
claim, header = JWT.decode(jwt, @key, true, algorithm: 'HS256')
expect(claim["iss"]).to eq '[email protected]'
expect(claim["scope"]).to eq 'https://www.googleapis.com/auth/userinfo.profile'
expect(claim["aud"]).to eq 'https://accounts.google.com/o/oauth2/token'
Expand Down