2015-03-30 21:30:27 +02:00
|
|
|
package providers
|
|
|
|
|
2015-06-23 13:23:39 +02:00
|
|
|
import (
|
2020-05-05 17:53:33 +02:00
|
|
|
"context"
|
|
|
|
|
2020-04-28 08:46:46 +02:00
|
|
|
"github.com/coreos/go-oidc"
|
2020-03-29 15:54:36 +02:00
|
|
|
"github.com/oauth2-proxy/oauth2-proxy/pkg/apis/sessions"
|
2015-06-23 13:23:39 +02:00
|
|
|
)
|
|
|
|
|
2018-12-20 12:37:59 +02:00
|
|
|
// Provider represents an upstream identity provider implementation
|
2015-03-30 21:30:27 +02:00
|
|
|
type Provider interface {
|
|
|
|
Data() *ProviderData
|
2020-05-05 17:53:33 +02:00
|
|
|
GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error)
|
|
|
|
GetUserName(ctx context.Context, s *sessions.SessionState) (string, error)
|
|
|
|
GetPreferredUsername(ctx context.Context, s *sessions.SessionState) (string, error)
|
|
|
|
Redeem(ctx context.Context, redirectURI, code string) (*sessions.SessionState, error)
|
2015-08-20 12:07:02 +02:00
|
|
|
ValidateGroup(string) bool
|
2020-05-05 17:53:33 +02:00
|
|
|
ValidateSessionState(ctx context.Context, s *sessions.SessionState) bool
|
2015-06-06 20:15:43 +02:00
|
|
|
GetLoginURL(redirectURI, finalRedirect string) string
|
2020-05-05 17:53:33 +02:00
|
|
|
RefreshSessionIfNeeded(ctx context.Context, s *sessions.SessionState) (bool, error)
|
|
|
|
CreateSessionStateFromBearerToken(ctx context.Context, rawIDToken string, idToken *oidc.IDToken) (*sessions.SessionState, error)
|
2015-03-30 21:30:27 +02:00
|
|
|
}
|
|
|
|
|
2018-12-20 12:37:59 +02:00
|
|
|
// New provides a new Provider based on the configured provider string
|
2015-03-30 21:30:27 +02:00
|
|
|
func New(provider string, p *ProviderData) Provider {
|
|
|
|
switch provider {
|
2015-04-18 00:33:17 +02:00
|
|
|
case "linkedin":
|
|
|
|
return NewLinkedInProvider(p)
|
2016-06-23 14:29:44 +02:00
|
|
|
case "facebook":
|
|
|
|
return NewFacebookProvider(p)
|
2015-05-21 05:23:48 +02:00
|
|
|
case "github":
|
|
|
|
return NewGitHubProvider(p)
|
2019-07-28 15:54:39 +02:00
|
|
|
case "keycloak":
|
|
|
|
return NewKeycloakProvider(p)
|
2015-11-09 10:28:34 +02:00
|
|
|
case "azure":
|
|
|
|
return NewAzureProvider(p)
|
2016-02-17 14:19:52 +02:00
|
|
|
case "gitlab":
|
|
|
|
return NewGitLabProvider(p)
|
2017-05-09 20:20:35 +02:00
|
|
|
case "oidc":
|
|
|
|
return NewOIDCProvider(p)
|
2019-03-20 15:44:51 +02:00
|
|
|
case "login.gov":
|
|
|
|
return NewLoginGovProvider(p)
|
2019-08-16 15:53:22 +02:00
|
|
|
case "bitbucket":
|
|
|
|
return NewBitbucketProvider(p)
|
2019-06-05 18:59:04 +02:00
|
|
|
case "nextcloud":
|
|
|
|
return NewNextcloudProvider(p)
|
2020-01-15 13:09:34 +02:00
|
|
|
case "digitalocean":
|
|
|
|
return NewDigitalOceanProvider(p)
|
2015-03-30 21:30:27 +02:00
|
|
|
default:
|
|
|
|
return NewGoogleProvider(p)
|
|
|
|
}
|
|
|
|
}
|