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

changes as requested. #3

Open
wants to merge 9 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
16 changes: 8 additions & 8 deletions lib/azure_jwt_auth/authenticable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def authenticate!
unauthorize! unless JwtManager.providers

JwtManager.providers.each do |_uid, provider|
token = JwtManager.new(request, provider.uid)

if token.valid?
@current_user = entity_from_token_payload(token.payload)
break
begin
token = JwtManager.new(request, provider.uid)
if token.valid?
@current_user = entity_from_token_payload(token.payload)
break
end
rescue => error
Rails.logger.info(error) if defined? Rails
end
rescue => error
Rails.logger.info(error) if defined? Rails
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore this line please. We always put empty line before and after a block.

unauthorize! unless @current_user
end

Expand Down
15 changes: 13 additions & 2 deletions lib/azure_jwt_auth/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ def initialize(uid, config_uri, validations={})
@config_uri = config_uri
@validations = validations

http = Net::HTTP.new(URI(config_uri).host, URI(config_uri).port)

begin
@config = JSON.parse(Net::HTTP.get(URI(config_uri)))
uri = URI.parse(config_uri)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you can pass uri directly: request = Net::HTTP::Get.new(uri)

response = http.request(request)
@config = JSON.parse(response.body)
rescue JSON::ParserError
raise InvalidProviderConfig, "config_uri response is not valid for provider: #{uid}"
end
Expand All @@ -22,7 +29,11 @@ def initialize(uid, config_uri, validations={})

def load_keys
uri = URI(@config['jwks_uri'])
keys = JSON.parse(Net::HTTP.get(uri))['keys']
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
keys = JSON.parse(response.body)['keys']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated. I think that it's better to create a private function like this:

def make_get_request(url)
  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Get.new(uri.request_uri)
  response = http.request(request)
  JSON.parse(response.body)
end


@keys = {}
keys.each do |key|
Expand Down