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

[Bug] Net::HTTP is returning 403 Forbidden on getting Apple Auth Keys #31

Open
yasalmasri opened this issue Nov 25, 2021 · 3 comments
Open
Labels
bug Something isn't working

Comments

@yasalmasri
Copy link

yasalmasri commented Nov 25, 2021

Bug report:

  • Expected Behavior:
    Production Environment when verifying user identity, request to Apple Auth Keys should return 200 response code.
    I tried to hit the same URL using RestClient and got 200 response code with the expected response body.

  • Actual Behavior:
    Production Environment when verifying user identity, request to Apple Auth Keys is returning 403 Forbidden.

  • Steps to Reproduce:

    1. Deploy a rails app
    2. rails console
    3. Net::HTTP.get(URI.parse('https://appleid.apple.com/auth/keys'))
    4. Response code is 403
  • Version of the repo:
    AppleAuth 1.0.0

  • Ruby and Rails Version:
    ruby-2.7.1 rails-6.0.4.1

@yasalmasri yasalmasri added the bug Something isn't working label Nov 25, 2021
@Gnash-Obial
Copy link

Hey, have you solved the issue? I am encountering this issue as well.

@yasalmasri
Copy link
Author

@Gnash-Obial
check your config/initializers/apple_auth.rb and make sure you escape the line brake:

config.apple_private_key = ENV.fetch('APPLE_PRIVATE_KEY', 'apple_private_key').gsub("\\n", "\n")

I also override the method by using RestClient to do this request as it does not require authentication:

module AppleAuth
  class UserIdentity
    private

    def apple_key_hash
      certificate = JSON.parse(response)
      matching_key = certificate['keys'].select { |key| key['kid'] == jwt_kid }
      ActiveSupport::HashWithIndifferentAccess.new(matching_key.first)
    end

    def response
      @response ||= RestClient.get(APPLE_KEY_URL).body
    end
  end
end

@langelone
Copy link

It's a Server Name Indication problem. Change HTTP client

AppleAuth::UserIdentity.class_eval do

  private
  
  def apple_key_hash
    response = Faraday.get(AppleAuth::UserIdentity::APPLE_KEY_URL).body
    certificate = JSON.parse(response)
    matching_key = certificate['keys'].select { |key| key['kid'] == jwt_kid }
    ActiveSupport::HashWithIndifferentAccess.new(matching_key.first)
  end

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants