2015-03-30 21:30:27 +02:00
|
|
|
package providers
|
|
|
|
|
|
|
|
import (
|
2020-02-15 15:44:39 +02:00
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
2015-03-30 21:30:27 +02:00
|
|
|
"net/url"
|
2020-03-14 11:58:29 +02:00
|
|
|
|
|
|
|
"github.com/pusher/oauth2_proxy/pkg/logger"
|
2015-03-30 21:30:27 +02:00
|
|
|
)
|
|
|
|
|
2018-12-20 12:37:59 +02:00
|
|
|
// ProviderData contains information required to configure all implementations
|
|
|
|
// of OAuth2 providers
|
2015-03-30 21:30:27 +02:00
|
|
|
type ProviderData struct {
|
2015-11-09 10:28:34 +02:00
|
|
|
ProviderName string
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
2020-02-15 15:44:39 +02:00
|
|
|
ClientSecretFile string
|
2015-11-09 10:28:34 +02:00
|
|
|
LoginURL *url.URL
|
|
|
|
RedeemURL *url.URL
|
|
|
|
ProfileURL *url.URL
|
|
|
|
ProtectedResource *url.URL
|
|
|
|
ValidateURL *url.URL
|
|
|
|
Scope string
|
2020-03-14 11:53:43 +02:00
|
|
|
Prompt string
|
2015-11-09 10:28:34 +02:00
|
|
|
ApprovalPrompt string
|
2015-03-30 21:30:27 +02:00
|
|
|
}
|
|
|
|
|
2018-12-20 12:37:59 +02:00
|
|
|
// Data returns the ProviderData
|
2015-03-30 21:30:27 +02:00
|
|
|
func (p *ProviderData) Data() *ProviderData { return p }
|
2020-02-15 15:44:39 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|