gitea源码

source.go 1.2KB

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