Skip to content

Commit

Permalink
handle secret hash for multiple issuers
Browse files Browse the repository at this point in the history
  • Loading branch information
abramin committed Jun 15, 2017
1 parent f7c0591 commit 408eb2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/omniauth/jwt/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Omniauth
module JWT
VERSION = "1.1.1"
VERSION = "1.2.0"
end
end
8 changes: 8 additions & 0 deletions lib/omniauth/strategies/jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def callback_phase
def secret
if options.secret.is_a?(String)
options.secret
elsif options.secret.is_a?(Hash)
issuer_specific_secret
else
secret_lookup.secret
end
Expand All @@ -77,6 +79,12 @@ def secret_lookup
def uid_lookup
@uid_lookup ||= options.uid_claim.new(request)
end

def issuer_specific_secret
unverified_token = ::JWT.decode(request.params['jwt'], nil, false)[0]
iss = unverified_token['iss']
options.secret[iss]
end
end

class Jwt < JWT; end
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/omniauth/strategies/jwt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,17 @@ def uid(decoded)
expect(last_response.status).to eq(302)
end
end

describe 'secret' do
context 'multiple issuers' do
let(:args) { [{ issuer_1: 'secret_1', issuer_2: 'secret_2' }, {auth_url: 'http://example.com/login'}] }

it 'should assign the uid' do
encoded = JWT.encode({name: 'Steve', email: 'dude@awesome.com', iss: 'issuer_1'}, 'secret_1')
get '/auth/jwt/callback?jwt=' + encoded
expect(response_json["uid"]).to eq('dude@awesome.com')
end
end
end
end
end

0 comments on commit 408eb2d

Please sign in to comment.