43 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
| package providers
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"github.com/pusher/oauth2_proxy/pkg/logger"
 | |
| 	"io/ioutil"
 | |
| 	"net/url"
 | |
| )
 | |
| 
 | |
| // ProviderData contains information required to configure all implementations
 | |
| // of OAuth2 providers
 | |
| type ProviderData struct {
 | |
| 	ProviderName      string
 | |
| 	ClientID          string
 | |
| 	ClientSecret      string
 | |
| 	ClientSecretFile  string
 | |
| 	LoginURL          *url.URL
 | |
| 	RedeemURL         *url.URL
 | |
| 	ProfileURL        *url.URL
 | |
| 	ProtectedResource *url.URL
 | |
| 	ValidateURL       *url.URL
 | |
| 	Scope             string
 | |
| 	Prompt            string
 | |
| 	ApprovalPrompt    string
 | |
| }
 | |
| 
 | |
| // Data returns the ProviderData
 | |
| func (p *ProviderData) Data() *ProviderData { return p }
 | |
| 
 | |
| func (p *ProviderData) GetClientSecret() (ClientSecret string, err error) {
 | |
| 	if p.ClientSecret != "" || p.ClientSecretFile == "" {
 | |
| 		return p.ClientSecret, nil
 | |
| 	}
 | |
| 
 | |
| 	// Getting ClientSecret can fail in runtime so we need to report it without returning the file name to the user
 | |
| 	fileClientSecret, err := ioutil.ReadFile(p.ClientSecretFile)
 | |
| 	if err != nil {
 | |
| 		logger.Printf("error reading client secret file %s: %s", p.ClientSecretFile, err)
 | |
| 		return "", errors.New("could not read client secret file")
 | |
| 	}
 | |
| 	return string(fileClientSecret), nil
 | |
| }
 |