github.com/greenpau/go-authcrunch@v1.1.4/pkg/idp/oauth/browser.go (about)

     1  // Copyright 2022 Paul Greenberg greenpau@outlook.com
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package oauth
    16  
    17  import (
    18  	"crypto/tls"
    19  	"net"
    20  	"net/http"
    21  	"time"
    22  )
    23  
    24  type browserConfig struct {
    25  	TLSInsecureSkipVerify bool
    26  }
    27  
    28  func (b *IdentityProvider) newBrowser() (*http.Client, error) {
    29  	/*
    30  	   cj, err := cookiejar.New(nil)
    31  	   if err != nil {
    32  	       return nil, err
    33  	   }
    34  	*/
    35  	tr := &http.Transport{
    36  		Proxy: http.ProxyFromEnvironment,
    37  		Dial: (&net.Dialer{
    38  			Timeout: 5 * time.Second,
    39  		}).Dial,
    40  		TLSHandshakeTimeout: 5 * time.Second,
    41  	}
    42  
    43  	if b.browserConfig != nil {
    44  		if b.browserConfig.TLSInsecureSkipVerify == true {
    45  			if tr.TLSClientConfig == nil {
    46  				tr.TLSClientConfig = &tls.Config{
    47  					InsecureSkipVerify: true,
    48  				}
    49  			} else {
    50  				tr.TLSClientConfig.InsecureSkipVerify = true
    51  			}
    52  		}
    53  	}
    54  
    55  	return &http.Client{
    56  		//Jar:       cj,
    57  		Timeout:   time.Second * 10,
    58  		Transport: tr,
    59  	}, nil
    60  }