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

Client requests use incomplete URL resulting in failure #3

Open
6 tasks done
znorris opened this issue Oct 30, 2021 · 7 comments
Open
6 tasks done

Client requests use incomplete URL resulting in failure #3

znorris opened this issue Oct 30, 2021 · 7 comments
Assignees
Labels
area/docs This issue affects Ory's documentation. bug Something is not working.

Comments

@znorris
Copy link

znorris commented Oct 30, 2021

Preflight checklist

Describe the bug

Ruby SDK does not properly generate a request URL, leaving out scheme and hostname. The http client library, Typhoeus, is unable to attempt the request because of this.

Reproducing the bug

Make a registration flow request using the SDK as documented. See relevant log output. Note the effective_url should include a scheme and hostname as well. The answer is somewhere near this URL builder in the generated code.

Relevant log output

Processing by Kratos::RegistrationController#index as */*
  Parameters: {"flow"=>"87e5fcbd-0ae4-44c6-9720-cf516bad181c"}
Calling API: V0alpha2Api.get_self_service_registration_flow ...
Closing connection -1
ETHON: performed EASY effective_url=/self-service/registration/flows?id=87e5fcbd-0ae4-44c6-9720-cf516bad181c response_code=0 return_code=url_malformat total_time=0.0
HTTP response body ~BEGIN~

~END~
Error when calling Kratos V0alpha2Api->get_self_service_registration_flow: URL using bad/illegal format or missing URL
HTTP status code: 0

Relevant configuration

No response

Version

0.8.0.alpha2

On which operating system are you observing this issue?

macOS

In which environment are you deploying?

Docker Compose

Additional Context

I've also tested version 0.7.6.alpha7

@znorris znorris added the bug Something is not working. label Oct 30, 2021
@znorris
Copy link
Author

znorris commented Oct 30, 2021

After stepping through the auto generated code I believe I have a better understanding of what's happening and a straight forward work-around.

The Kratos OpenAPI spec does not contain any Server Objects. The client generated data server_operation_index is being called by a function, server_url, to build the request URL. This is true even when the server_operation_index object is empty. That's likely a bug in the client generator. The good news is code does exist to build a request URL without having specified any server objects in the Kratos OpenAPI spec.

To do so implementers need to change the config.server_index setting from the default of 0 to nil. This will prevent the url building function from looking for data that doesn't exist in our case.

Existing code example

https://github.com/ory/kratos-client-ruby/blob/master/docs/V0alpha2Api.md#examples-12

require 'time'
require 'ory-kratos-client'

api_instance = OryKratosClient::V0alpha2Api.new
id = 'id_example' # String | The Registration Flow ID  The value for this parameter comes from `flow` URL Query parameter sent to your application (e.g. `/registration?flow=abcde`).
opts = {
  cookie: 'cookie_example' # String | HTTP Cookies  When using the SDK on the server side you must include the HTTP Cookie Header originally sent to your HTTP handler here.
}

begin
  # Get Registration Flow
  result = api_instance.get_self_service_registration_flow(id, opts)
  p result
rescue OryKratosClient::ApiError => e
  puts "Error when calling V0alpha2Api->get_self_service_registration_flow: #{e}"
end
}

begin
  # Get Registration Flow
  result = api_instance.get_self_service_registration_flow(id, opts)
  p result
rescue OryKratosClient::ApiError => e
  puts "Error when calling V0alpha2Api->get_self_service_registration_flow: #{e}"
end

Code example with work-around

# Modifies the kratos client configuration 'server_index' to ensure the URL building function doesn't
# look for non-existant OpenAPI server objects.

require 'time'
require 'ory-kratos-client'

OryKratosClient.configure do |config|
        config.server_index = nil
end

api_instance = OryKratosClient::V0alpha2Api.new
...

Thoughts on Kratos OpenAPI spec fix

Another possible solution may be to specify a Server Object in the Kratos OpenAPI spec? My example sets the hostname to the default used in the client config.

{
  "servers": [
    {
      "url": "http://localhost",
      "description": "Development server"
    }
  ]
}

Thoughts on OpenAPI Ruby client generator fix

  • Make default of config.server_index = nil when no Server Objects are specified in the spec
  • Require Server Objects in spec
  • Update documentation to cover this case

@aeneasr
Copy link
Member

aeneasr commented Nov 1, 2021

Thank you for investigating! Openapi released version 5.3.0, maybe it's fixed there already?

@nickodelon
Copy link

Bump, does not seem to be fixed, still getting the error unless I use a workaround

@Benehiko
Copy link

Hmm, maybe we can just add this somewhere in our Documentation until a fix is issued?
/cc @tomekpapiernik

@dotubutis
Copy link

@znorris Thanks so much for documenting this, it saved me a lot of time.

@aeneasr
Copy link
Member

aeneasr commented Oct 5, 2022

@tomekpapiernik @vinckr please check this

@aeneasr aeneasr added the area/docs This issue affects Ory's documentation. label Jul 27, 2023
@aeneasr
Copy link
Member

aeneasr commented Jul 27, 2023

We have since upgraded to SDK generator version 6 - can you please check if this is still a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs This issue affects Ory's documentation. bug Something is not working.
Projects
None yet
Development

No branches or pull requests

7 participants