aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2024-02-24 05:18:49 +0100
committerGitHub <noreply@github.com>2024-02-24 12:18:49 +0800
commit4ba642d07d50d7eb42ae33cd6f1f7f2c82c02a40 (patch)
tree52f879a6788100115c2127d62c0c6182cd96ad41 /models
parent875f5ea6d83c8371f309df99654ca3556623004c (diff)
downloadgitea-4ba642d07d50d7eb42ae33cd6f1f7f2c82c02a40.tar.gz
gitea-4ba642d07d50d7eb42ae33cd6f1f7f2c82c02a40.zip
Revert "Support SAML authentication (#25165)" (#29358)
This reverts #25165 (5bb8d1924d77c675467694de26697b876d709a17), as there was a chance some important reviews got missed. so after reverting this patch it will be resubmitted for reviewing again https://github.com/go-gitea/gitea/pull/25165#issuecomment-1960670242 temporary Open #5512 again
Diffstat (limited to 'models')
-rw-r--r--models/auth/oauth2.go20
-rw-r--r--models/auth/source.go38
2 files changed, 15 insertions, 43 deletions
diff --git a/models/auth/oauth2.go b/models/auth/oauth2.go
index a252458d4e..9d53fffc78 100644
--- a/models/auth/oauth2.go
+++ b/models/auth/oauth2.go
@@ -8,7 +8,6 @@ import (
"crypto/sha256"
"encoding/base32"
"encoding/base64"
- "encoding/gob"
"fmt"
"net"
"net/url"
@@ -82,10 +81,6 @@ func Init(ctx context.Context) error {
builtinAllClientIDs = append(builtinAllClientIDs, clientID)
}
- // This is needed in order to encode and store the struct in the goth/gothic session
- // during the process of linking the external user.
- gob.Register(LinkAccountUser{})
-
var registeredApps []*OAuth2Application
if err := db.GetEngine(ctx).In("client_id", builtinAllClientIDs).Find(&registeredApps); err != nil {
return err
@@ -610,6 +605,21 @@ func (err ErrOAuthApplicationNotFound) Unwrap() error {
return util.ErrNotExist
}
+// GetActiveOAuth2SourceByName returns a OAuth2 AuthSource based on the given name
+func GetActiveOAuth2SourceByName(ctx context.Context, name string) (*Source, error) {
+ authSource := new(Source)
+ has, err := db.GetEngine(ctx).Where("name = ? and type = ? and is_active = ?", name, OAuth2, true).Get(authSource)
+ if err != nil {
+ return nil, err
+ }
+
+ if !has {
+ return nil, fmt.Errorf("oauth2 source not found, name: %q", name)
+ }
+
+ return authSource, nil
+}
+
func DeleteOAuth2RelictsByUserID(ctx context.Context, userID int64) error {
deleteCond := builder.Select("id").From("oauth2_grant").Where(builder.Eq{"oauth2_grant.user_id": userID})
diff --git a/models/auth/source.go b/models/auth/source.go
index bc564d35ba..1bdde8235c 100644
--- a/models/auth/source.go
+++ b/models/auth/source.go
@@ -14,7 +14,6 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
- "github.com/markbates/goth"
"xorm.io/builder"
"xorm.io/xorm"
"xorm.io/xorm/convert"
@@ -33,7 +32,6 @@ const (
DLDAP // 5
OAuth2 // 6
SSPI // 7
- SAML // 8
)
// String returns the string name of the LoginType
@@ -54,7 +52,6 @@ var Names = map[Type]string{
PAM: "PAM",
OAuth2: "OAuth2",
SSPI: "SPNEGO with SSPI",
- SAML: "SAML",
}
// Config represents login config as far as the db is concerned
@@ -124,12 +121,6 @@ type Source struct {
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
}
-// LinkAccountUser is used to link an external user with a local user
-type LinkAccountUser struct {
- Type Type
- GothUser goth.User
-}
-
// TableName xorm will read the table name from this method
func (Source) TableName() string {
return "login_source"
@@ -189,11 +180,6 @@ func (source *Source) IsSSPI() bool {
return source.Type == SSPI
}
-// IsSAML returns true of this source is of the SAML type.
-func (source *Source) IsSAML() bool {
- return source.Type == SAML
-}
-
// HasTLS returns true of this source supports TLS.
func (source *Source) HasTLS() bool {
hasTLSer, ok := source.Cfg.(HasTLSer)
@@ -406,27 +392,3 @@ func IsErrSourceInUse(err error) bool {
func (err ErrSourceInUse) Error() string {
return fmt.Sprintf("login source is still used by some users [id: %d]", err.ID)
}
-
-// GetActiveAuthProviderSources returns all activated sources
-func GetActiveAuthProviderSources(ctx context.Context, authType Type) ([]*Source, error) {
- sources := make([]*Source, 0, 1)
- if err := db.GetEngine(ctx).Where("is_active = ? and type = ?", true, authType).Find(&sources); err != nil {
- return nil, err
- }
- return sources, nil
-}
-
-// GetActiveAuthSourceByName returns an AuthSource based on the given name and type
-func GetActiveAuthSourceByName(ctx context.Context, name string, authType Type) (*Source, error) {
- authSource := new(Source)
- has, err := db.GetEngine(ctx).Where("name = ? and type = ? and is_active = ?", name, authType, true).Get(authSource)
- if err != nil {
- return nil, err
- }
-
- if !has {
- return nil, fmt.Errorf("auth source not found, name: %q", name)
- }
-
- return authSource, nil
-}