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

Configuring TLS with go-swagger client #2320

Open
A112833 opened this issue Jun 25, 2020 · 2 comments
Open

Configuring TLS with go-swagger client #2320

A112833 opened this issue Jun 25, 2020 · 2 comments

Comments

@A112833
Copy link

A112833 commented Jun 25, 2020

Problem statement

I am struggling to get TLS working with my go-swagger client, getting reply: 400 No required SSL certificate was sent

the setup of cert and key works fine in a vanilla http client where I do something like this:
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}

But I am failing getting this setup for my go-swagger client.
Would you have any code examples pls?

@casualjim
Copy link
Member

for this client: https://github.com/go-swagger/go-swagger/blob/master/examples/todo-list/client/todo_list_client.go

You can use this method: https://github.com/go-openapi/runtime/blob/master/client/runtime.go#L282

import (
  todos "github.com/go-swagger/go-swagger/examples/todo-list/client"
  transport "github.com/go-openapi/runtime/client"
)

tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{TLSClientConfig: tlsConfig}
httpClient := &http.Client{Transport: transport}

cl := client.New(transport.New(todos.DefaultHost, todos.DefaultBasePath, todos.DefaultSchemes, httpClient)

@A112833
Copy link
Author

A112833 commented Jun 26, 2020

That worked (with slight change to call)

   transport := &http.Transport{TLSClientConfig: tlsConfig}
httpClient := &http.Client{Transport: transport}
tr := httptransport.NewWithClient(apiclient.DefaultHost, apiclient.DefaultBasePath, apiclient.DefaultSchemes, httpClient)
client := apiclient.New(tr, nil)

Thank you, much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants