MCPcopy
hub / github.com/smallstep/cli / NewServer

Method NewServer

command/oauth/cmd.go:729–763  ·  view source on GitHub ↗

NewServer creates http server

()

Source from the content-addressed store, hash-verified

727
728// NewServer creates http server
729func (o *oauth) NewServer() (*httptest.Server, error) {
730 if o.CallbackListener == "" {
731 return httptest.NewServer(o), nil
732 }
733 host, port, err := net.SplitHostPort(o.CallbackListener)
734 if err != nil {
735 return nil, err
736 }
737 if host == "" {
738 host = "127.0.0.1"
739 }
740 l, err := net.Listen("tcp", net.JoinHostPort(host, port))
741 if err != nil {
742 return nil, errors.Wrapf(err, "error listening on %s", o.CallbackListener)
743 }
744 srv := &httptest.Server{
745 Listener: l,
746 Config: &http.Server{
747 Handler: o,
748 ReadHeaderTimeout: 15 * time.Second,
749 },
750 }
751 srv.Start()
752
753 // Update server url to use for example http://localhost:port
754 if host != "127.0.0.1" {
755 _, p, err := net.SplitHostPort(l.Addr().String())
756 if err != nil {
757 return nil, errors.Wrapf(err, "error parsing %s", l.Addr().String())
758 }
759 srv.URL = "http://" + host + ":" + p
760 }
761
762 return srv, nil
763}
764
765// DoLoopbackAuthorization performs the log in into the identity provider
766// opening a browser and using a redirect_uri in a loopback IP address

Callers 1

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected