2015-03-30 15:30:27 -04:00
|
|
|
package providers
|
|
|
|
|
|
|
|
import (
|
2020-02-15 14:44:39 +01:00
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
2015-03-30 15:30:27 -04:00
|
|
|
"net/url"
|
2020-03-14 05:58:29 -04:00
|
|
|
|
2020-03-29 14:54:36 +01:00
|
|
|
"github.com/oauth2-proxy/oauth2-proxy/pkg/logger"
|
2015-03-30 15:30:27 -04:00
|
|
|
)
|
|
|
|
|
2018-12-20 10:37:59 +00:00
|
|
|
// ProviderData contains information required to configure all implementations
|
|
|
|
// of OAuth2 providers
|
2015-03-30 15:30:27 -04:00
|
|
|
type ProviderData struct {
|
2015-11-09 09:28:34 +01:00
|
|
|
ProviderName string
|
|
|
|
LoginURL *url.URL
|
|
|
|
RedeemURL *url.URL
|
|
|
|
ProfileURL *url.URL
|
|
|
|
ProtectedResource *url.URL
|
|
|
|
ValidateURL *url.URL
|
2020-03-17 18:57:33 +01:00
|
|
|
// Auth request params & related, see
|
|
|
|
//https://openid.net/specs/openid-connect-basic-1_0.html#rfc.section.2.1.1.1
|
|
|
|
AcrValues string
|
|
|
|
ApprovalPrompt string // NOTE: Renamed to "prompt" in OAuth2
|
|
|
|
ClientID string
|
|
|
|
ClientSecret string
|
|
|
|
ClientSecretFile string
|
|
|
|
Scope string
|
|
|
|
Prompt string
|
2015-03-30 15:30:27 -04:00
|
|
|
}
|
|
|
|
|
2018-12-20 10:37:59 +00:00
|
|
|
// Data returns the ProviderData
|
2015-03-30 15:30:27 -04:00
|
|
|
func (p *ProviderData) Data() *ProviderData { return p }
|
2020-02-15 14:44:39 +01:00
|
|
|
|
2020-04-14 17:36:44 +09:00
|
|
|
func (p *ProviderData) GetClientSecret() (clientSecret string, err error) {
|
2020-02-15 14:44:39 +01:00
|
|
|
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
|
|
|
|
}
|