github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/oauth2/oauth2.go (about)

     1  package oauth2
     2  
     3  import (
     4  	"golang.org/x/oauth2"
     5  
     6  	"github.com/johnnyeven/libtools/conf/presets"
     7  )
     8  
     9  type OAuthConfig struct {
    10  	ClientID     string           `conf:"env"`
    11  	ClientSecret presets.Password `conf:"env"`
    12  	RedirectURL  string           `conf:"env"`
    13  	Scopes       []string
    14  	oauth2.Endpoint
    15  }
    16  
    17  func (o OAuthConfig) Init() {
    18  	oauth2.RegisterBrokenAuthHeaderProvider(o.Endpoint.TokenURL)
    19  }
    20  
    21  func (o OAuthConfig) Get() *oauth2.Config {
    22  	return &oauth2.Config{
    23  		ClientID:     o.ClientID,
    24  		ClientSecret: string(o.ClientSecret),
    25  		Endpoint:     o.Endpoint,
    26  		RedirectURL:  o.RedirectURL,
    27  		Scopes:       o.Scopes,
    28  	}
    29  }