code.gitea.io/gitea@v1.21.7/services/auth/source/oauth2/providers_openid.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/setting" 11 "code.gitea.io/gitea/modules/svg" 12 13 "github.com/markbates/goth" 14 "github.com/markbates/goth/providers/openidConnect" 15 ) 16 17 // OpenIDProvider is a GothProvider for OpenID 18 type OpenIDProvider struct{} 19 20 // Name provides the technical name for this provider 21 func (o *OpenIDProvider) Name() string { 22 return "openidConnect" 23 } 24 25 // DisplayName returns the friendly name for this provider 26 func (o *OpenIDProvider) DisplayName() string { 27 return "OpenID Connect" 28 } 29 30 // IconHTML returns icon HTML for this provider 31 func (o *OpenIDProvider) IconHTML(size int) template.HTML { 32 return svg.RenderHTML("gitea-openid", size, "gt-mr-3") 33 } 34 35 // CreateGothProvider creates a GothProvider from this Provider 36 func (o *OpenIDProvider) CreateGothProvider(providerName, callbackURL string, source *Source) (goth.Provider, error) { 37 scopes := setting.OAuth2Client.OpenIDConnectScopes 38 if len(scopes) == 0 { 39 scopes = append(scopes, source.Scopes...) 40 } 41 42 provider, err := openidConnect.New(source.ClientID, source.ClientSecret, callbackURL, source.OpenIDConnectAutoDiscoveryURL, scopes...) 43 if err != nil { 44 log.Warn("Failed to create OpenID Connect Provider with name '%s' with url '%s': %v", providerName, source.OpenIDConnectAutoDiscoveryURL, err) 45 } 46 return provider, err 47 } 48 49 // CustomURLSettings returns the custom url settings for this provider 50 func (o *OpenIDProvider) CustomURLSettings() *CustomURLSettings { 51 return nil 52 } 53 54 var _ GothProvider = &OpenIDProvider{} 55 56 func init() { 57 RegisterGothProvider(&OpenIDProvider{}) 58 }