Skip to content

Commit

Permalink
Support ruby-jwt 2.0 (#93)
Browse files Browse the repository at this point in the history
* Support ruby-jwt 2.0

This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.

* Use specific version of JRuby to fix CI for now
  • Loading branch information
jurriaan authored and dazuma committed Oct 4, 2017
1 parent d5d3445 commit c9d21b3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
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 'app@example.com'
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 'app@example.com'
expect(claim["prn"]).to eq 'user@example.com'
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 'app@example.com'
expect(claim["prn"]).to eq 'user@example.com'
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 'app@example.com'
expect(claim["sub"]).to eq 'user@example.com'
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 'app@example.com'
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

0 comments on commit c9d21b3

Please sign in to comment.