opengist/internal/auth/oauth/provider.go

47 lines
965 B
Go
Raw Normal View History

2025-01-11 19:17:01 +00:00
package oauth
import (
"github.com/rs/zerolog/log"
"github.com/thomiceli/opengist/internal/db"
"net/url"
)
const (
GitHubProviderString = "github"
GitLabProviderString = "gitlab"
GiteaProviderString = "gitea"
OpenIDConnectString = "openid-connect"
)
type Provider interface {
RegisterProvider() error
SSHKeysURL(user *db.User) string
GetProviderUserID(user *db.User) bool
SetProviderUserID() error
GetAvatarURL(user *db.User) string
}
func DefineProvider(provider string, url string) Provider {
switch provider {
case GitHubProviderString:
return NewGitHubProvider(url)
case GitLabProviderString:
return NewGitLabProvider(url)
case GiteaProviderString:
return NewGiteaProvider(url)
case OpenIDConnectString:
return NewOIDCProvider(url)
}
return nil
}
func urlJoin(base string, elem ...string) string {
joined, err := url.JoinPath(base, elem...)
if err != nil {
log.Error().Err(err).Msg("Cannot join url")
}
return joined
}