mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-14 20:02:42 +00:00
47 lines
965 B
Go
47 lines
965 B
Go
|
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
|
||
|
}
|