2021-08-06 02:11:08 +01:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-08-06 02:11:08 +01:00
|
|
|
|
|
|
|
|
package oauth2
|
|
|
|
|
|
2023-06-13 12:51:02 +02:00
|
|
|
import (
|
|
|
|
|
"html/template"
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
"code.gitea.io/gitea/modules/svg"
|
|
|
|
|
)
|
2023-06-09 00:35:29 +08:00
|
|
|
|
2021-08-06 02:11:08 +01:00
|
|
|
// BaseProvider represents a common base for Provider
|
|
|
|
|
type BaseProvider struct {
|
|
|
|
|
name string
|
|
|
|
|
displayName string
|
2025-07-11 02:35:59 +08:00
|
|
|
|
|
|
|
|
// TODO: maybe some providers also support SSH public keys, then they can set this to true
|
|
|
|
|
supportSSHPublicKey bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *BaseProvider) SupportSSHPublicKey() bool {
|
|
|
|
|
return b.supportSSHPublicKey
|
2021-08-06 02:11:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Name provides the technical name for this provider
|
|
|
|
|
func (b *BaseProvider) Name() string {
|
|
|
|
|
return b.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DisplayName returns the friendly name for this provider
|
|
|
|
|
func (b *BaseProvider) DisplayName() string {
|
|
|
|
|
return b.displayName
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 12:51:02 +02:00
|
|
|
// IconHTML returns icon HTML for this provider
|
2023-09-19 23:47:13 +02:00
|
|
|
func (b *BaseProvider) IconHTML(size int) template.HTML {
|
2023-06-13 12:51:02 +02:00
|
|
|
svgName := "gitea-" + b.name
|
|
|
|
|
switch b.name {
|
|
|
|
|
case "gplus":
|
|
|
|
|
svgName = "gitea-google"
|
|
|
|
|
case "github":
|
|
|
|
|
svgName = "octicon-mark-github"
|
|
|
|
|
}
|
2026-04-01 18:20:57 +05:30
|
|
|
svgHTML := svg.RenderHTML(svgName, size)
|
2023-06-13 12:51:02 +02:00
|
|
|
if svgHTML == "" {
|
|
|
|
|
log.Error("No SVG icon for oauth2 provider %q", b.name)
|
2026-04-01 18:20:57 +05:30
|
|
|
svgHTML = svg.RenderHTML("gitea-openid", size)
|
2023-06-09 00:35:29 +08:00
|
|
|
}
|
2023-06-13 12:51:02 +02:00
|
|
|
return svgHTML
|
2021-08-06 02:11:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CustomURLSettings returns the custom url settings for this provider
|
|
|
|
|
func (b *BaseProvider) CustomURLSettings() *CustomURLSettings {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 00:35:29 +08:00
|
|
|
var _ Provider = &BaseProvider{}
|