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

     1  // Copyright 2021 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package oauth2
     5  
     6  import (
     7  	"code.gitea.io/gitea/models/auth"
     8  	"code.gitea.io/gitea/modules/json"
     9  )
    10  
    11  // Source holds configuration for the OAuth2 login source.
    12  type Source struct {
    13  	Provider                      string
    14  	ClientID                      string
    15  	ClientSecret                  string
    16  	OpenIDConnectAutoDiscoveryURL string
    17  	CustomURLMapping              *CustomURLMapping
    18  	IconURL                       string
    19  
    20  	Scopes              []string
    21  	RequiredClaimName   string
    22  	RequiredClaimValue  string
    23  	GroupClaimName      string
    24  	AdminGroup          string
    25  	GroupTeamMap        string
    26  	GroupTeamMapRemoval bool
    27  	RestrictedGroup     string
    28  	SkipLocalTwoFA      bool `json:",omitempty"`
    29  
    30  	// reference to the authSource
    31  	authSource *auth.Source
    32  }
    33  
    34  // FromDB fills up an OAuth2Config from serialized format.
    35  func (source *Source) FromDB(bs []byte) error {
    36  	return json.UnmarshalHandleDoubleEncode(bs, &source)
    37  }
    38  
    39  // ToDB exports an SMTPConfig to a serialized format.
    40  func (source *Source) ToDB() ([]byte, error) {
    41  	return json.Marshal(source)
    42  }
    43  
    44  // SetAuthSource sets the related AuthSource
    45  func (source *Source) SetAuthSource(authSource *auth.Source) {
    46  	source.authSource = authSource
    47  }
    48  
    49  func init() {
    50  	auth.RegisterTypeConfig(auth.OAuth2, &Source{})
    51  }