code.gitea.io/gitea@v1.21.7/services/auth/source/oauth2/providers_base.go (about)

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package oauth2
     5  
     6  import (
     7  	"html/template"
     8  
     9  	"code.gitea.io/gitea/modules/log"
    10  	"code.gitea.io/gitea/modules/svg"
    11  )
    12  
    13  // BaseProvider represents a common base for Provider
    14  type BaseProvider struct {
    15  	name        string
    16  	displayName string
    17  }
    18  
    19  // Name provides the technical name for this provider
    20  func (b *BaseProvider) Name() string {
    21  	return b.name
    22  }
    23  
    24  // DisplayName returns the friendly name for this provider
    25  func (b *BaseProvider) DisplayName() string {
    26  	return b.displayName
    27  }
    28  
    29  // IconHTML returns icon HTML for this provider
    30  func (b *BaseProvider) IconHTML(size int) template.HTML {
    31  	svgName := "gitea-" + b.name
    32  	switch b.name {
    33  	case "gplus":
    34  		svgName = "gitea-google"
    35  	case "github":
    36  		svgName = "octicon-mark-github"
    37  	}
    38  	svgHTML := svg.RenderHTML(svgName, size, "gt-mr-3")
    39  	if svgHTML == "" {
    40  		log.Error("No SVG icon for oauth2 provider %q", b.name)
    41  		svgHTML = svg.RenderHTML("gitea-openid", size, "gt-mr-3")
    42  	}
    43  	return svgHTML
    44  }
    45  
    46  // CustomURLSettings returns the custom url settings for this provider
    47  func (b *BaseProvider) CustomURLSettings() *CustomURLSettings {
    48  	return nil
    49  }
    50  
    51  var _ Provider = &BaseProvider{}