Search code examples
ruby-on-railsauthenticationcurlpostmanauth0

Auth0 Ruby on Rails TCP Error


I am using Auth0's Ruby on Rails API Sample as boilerplate to set up authentication with a new app. Everything is working up to but not including the "Test Your API with cURL" step on the second page of the instructions.

I have tried testing both with cURL and with Postman, and both times I receive the follwoing error:

Errno::ECONNREFUSED in PrivateController#private. Failed to open TCP connection to :443 (Connection refused - connect(2) for nil port 443)

The highlighted line of the error is the following: jwks_raw = Net::HTTP.get URI("https://#{Rails.application.secrets.auth0_domain}/.well-known/jwks.json").

I receive the same error when I clone the sample repo directly and attempt testing with my Access Token, so it seems that it is possibly an oversight or outdated code in their example rather than some error with my incorporation of it into my own app.

How do I resolve this?


Solution

  • Make sure the auth0_domain secret is set when you are passing it to the rails app.

    If the value is empty, it will make your initial string an invalid URL, i.e. "https://#{Rails.application.secrets.auth0_domain}/.well-known/jwks.json" turns into "https:///.well-known/jwks.json".

    In my case I was using an empty environment variable, which returned nil:

    ENV['AUTH0_DOMAIN']
    => nil
    

    Hope this answer helps you!