2015-03-30 19:30:27 +00:00
|
|
|
package providers
|
|
|
|
|
2015-06-23 11:23:39 +00:00
|
|
|
import (
|
2019-05-05 12:33:13 +00:00
|
|
|
"github.com/pusher/oauth2_proxy/pkg/apis/sessions"
|
2019-05-24 16:06:48 +00:00
|
|
|
"github.com/pusher/oauth2_proxy/pkg/encryption"
|
2015-06-23 11:23:39 +00:00
|
|
|
)
|
|
|
|
|
2018-12-20 10:37:59 +00:00
|
|
|
// Provider represents an upstream identity provider implementation
|
2015-03-30 19:30:27 +00:00
|
|
|
type Provider interface {
|
|
|
|
Data() *ProviderData
|
2019-05-05 12:33:13 +00:00
|
|
|
GetEmailAddress(*sessions.SessionState) (string, error)
|
|
|
|
GetUserName(*sessions.SessionState) (string, error)
|
|
|
|
Redeem(string, string) (*sessions.SessionState, error)
|
2015-08-20 10:07:02 +00:00
|
|
|
ValidateGroup(string) bool
|
2019-05-05 12:33:13 +00:00
|
|
|
ValidateSessionState(*sessions.SessionState) bool
|
2015-06-06 18:15:43 +00:00
|
|
|
GetLoginURL(redirectURI, finalRedirect string) string
|
2019-05-05 12:33:13 +00:00
|
|
|
RefreshSessionIfNeeded(*sessions.SessionState) (bool, error)
|
2019-05-24 16:06:48 +00:00
|
|
|
SessionFromCookie(string, *encryption.Cipher) (*sessions.SessionState, error)
|
|
|
|
CookieForSession(*sessions.SessionState, *encryption.Cipher) (string, error)
|
2015-03-30 19:30:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 10:37:59 +00:00
|
|
|
// New provides a new Provider based on the configured provider string
|
2015-03-30 19:30:27 +00:00
|
|
|
func New(provider string, p *ProviderData) Provider {
|
|
|
|
switch provider {
|
2015-04-17 22:33:17 +00:00
|
|
|
case "linkedin":
|
|
|
|
return NewLinkedInProvider(p)
|
2016-06-23 12:29:44 +00:00
|
|
|
case "facebook":
|
|
|
|
return NewFacebookProvider(p)
|
2015-05-21 03:23:48 +00:00
|
|
|
case "github":
|
|
|
|
return NewGitHubProvider(p)
|
2015-11-09 08:28:34 +00:00
|
|
|
case "azure":
|
|
|
|
return NewAzureProvider(p)
|
2016-02-17 12:19:52 +00:00
|
|
|
case "gitlab":
|
|
|
|
return NewGitLabProvider(p)
|
2017-05-09 18:20:35 +00:00
|
|
|
case "oidc":
|
|
|
|
return NewOIDCProvider(p)
|
2019-03-20 13:44:51 +00:00
|
|
|
case "login.gov":
|
|
|
|
return NewLoginGovProvider(p)
|
2015-03-30 19:30:27 +00:00
|
|
|
default:
|
|
|
|
return NewGoogleProvider(p)
|
|
|
|
}
|
|
|
|
}
|