summaryrefslogtreecommitdiffstats
path: root/modules/auth/sso/user.go
blob: 48eebb1e915f01c7c0543b855053d02959cf5d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package sso

import (
	"net/http"

	"code.gitea.io/gitea/models"
)

// SignedInUser returns the user object of signed user.
// It returns a bool value to indicate whether user uses basic auth or not.
func SignedInUser(req *http.Request, w http.ResponseWriter, ds DataStore, sess SessionStore) (*models.User, bool) {
	if !models.HasEngine {
		return nil, false
	}

	// Try to sign in with each of the enabled plugins
	for _, ssoMethod := range Methods() {
		if !ssoMethod.IsEnabled() {
			continue
		}
		user := ssoMethod.VerifyAuthData(req, w, ds, sess)
		if user != nil {
			_, isBasic := ssoMethod.(*Basic)
			return user, isBasic
		}
	}

	return nil, false
}