2018-02-08 16:13:58 -06:00
|
|
|
package models
|
|
|
|
|
2018-03-19 16:09:49 -05:00
|
|
|
import (
|
2022-10-26 06:46:50 -05:00
|
|
|
"fmt"
|
2018-03-19 16:09:49 -05:00
|
|
|
"time"
|
2019-02-01 18:40:57 -06:00
|
|
|
|
2022-08-10 04:56:48 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
2022-06-28 07:32:25 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2020-12-11 04:44:44 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2022-06-28 07:32:25 -05:00
|
|
|
|
2019-02-01 18:40:57 -06:00
|
|
|
"golang.org/x/oauth2"
|
2018-03-19 16:09:49 -05:00
|
|
|
)
|
|
|
|
|
2018-02-08 16:13:58 -06:00
|
|
|
type UserAuth struct {
|
2019-02-01 18:40:57 -06:00
|
|
|
Id int64
|
|
|
|
UserId int64
|
|
|
|
AuthModule string
|
|
|
|
AuthId string
|
|
|
|
Created time.Time
|
|
|
|
OAuthAccessToken string
|
|
|
|
OAuthRefreshToken string
|
2021-12-14 08:22:10 -06:00
|
|
|
OAuthIdToken string
|
2019-02-01 18:40:57 -06:00
|
|
|
OAuthTokenType string
|
|
|
|
OAuthExpiry time.Time
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type ExternalUserInfo struct {
|
2019-02-01 18:40:57 -06:00
|
|
|
OAuthToken *oauth2.Token
|
2018-07-16 09:56:42 -05:00
|
|
|
AuthModule string
|
|
|
|
AuthId string
|
|
|
|
UserId int64
|
|
|
|
Email string
|
|
|
|
Login string
|
|
|
|
Name string
|
|
|
|
Groups []string
|
2022-08-10 04:56:48 -05:00
|
|
|
OrgRoles map[int64]org.RoleType
|
2018-07-16 09:56:42 -05:00
|
|
|
IsGrafanaAdmin *bool // This is a pointer to know if we should sync this or not (nil = ignore sync)
|
2019-05-21 06:52:49 -05:00
|
|
|
IsDisabled bool
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
|
|
|
|
2022-10-26 06:46:50 -05:00
|
|
|
func (e *ExternalUserInfo) String() string {
|
|
|
|
return fmt.Sprintf("%+v", *e)
|
|
|
|
}
|
|
|
|
|
2020-11-06 03:01:13 -06:00
|
|
|
type LoginInfo struct {
|
|
|
|
AuthModule string
|
2022-06-28 07:32:25 -05:00
|
|
|
User *user.User
|
2020-11-06 03:01:13 -06:00
|
|
|
ExternalUser ExternalUserInfo
|
|
|
|
LoginUsername string
|
|
|
|
HTTPStatus int
|
|
|
|
Error error
|
|
|
|
}
|
|
|
|
|
2021-01-19 10:55:53 -06:00
|
|
|
// RequestURIKey is used as key to save request URI in contexts
|
|
|
|
// (used for the Enterprise auditing feature)
|
|
|
|
type RequestURIKey struct{}
|
|
|
|
|
2018-02-08 16:13:58 -06:00
|
|
|
// ---------------------
|
|
|
|
// COMMANDS
|
|
|
|
|
|
|
|
type UpsertUserCommand struct {
|
2022-07-15 04:21:09 -05:00
|
|
|
ReqContext *ReqContext
|
|
|
|
ExternalUser *ExternalUserInfo
|
|
|
|
UserLookupParams
|
2018-02-08 16:13:58 -06:00
|
|
|
SignupAllowed bool
|
|
|
|
|
2022-06-28 07:32:25 -05:00
|
|
|
Result *user.User
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type SetAuthInfoCommand struct {
|
|
|
|
AuthModule string
|
|
|
|
AuthId string
|
|
|
|
UserId int64
|
2019-02-01 18:40:57 -06:00
|
|
|
OAuthToken *oauth2.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
type UpdateAuthInfoCommand struct {
|
|
|
|
AuthModule string
|
|
|
|
AuthId string
|
|
|
|
UserId int64
|
|
|
|
OAuthToken *oauth2.Token
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type DeleteAuthInfoCommand struct {
|
|
|
|
UserAuth *UserAuth
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------
|
|
|
|
// QUERIES
|
|
|
|
|
|
|
|
type LoginUserQuery struct {
|
2018-03-23 14:50:07 -05:00
|
|
|
ReqContext *ReqContext
|
|
|
|
Username string
|
|
|
|
Password string
|
2022-06-28 07:32:25 -05:00
|
|
|
User *user.User
|
2018-03-23 14:50:07 -05:00
|
|
|
IpAddress string
|
2020-09-04 07:54:59 -05:00
|
|
|
AuthModule string
|
2020-12-11 04:44:44 -06:00
|
|
|
Cfg *setting.Cfg
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetUserByAuthInfoQuery struct {
|
|
|
|
AuthModule string
|
|
|
|
AuthId string
|
2022-07-15 04:21:09 -05:00
|
|
|
UserLookupParams
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserLookupParams struct {
|
|
|
|
// Describes lookup order as well
|
|
|
|
UserID *int64 // if set, will try to find the user by id
|
|
|
|
Email *string // if set, will try to find the user by email
|
|
|
|
Login *string // if set, will try to find the user by login
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
|
|
|
|
2019-05-21 06:52:49 -05:00
|
|
|
type GetExternalUserInfoByLoginQuery struct {
|
|
|
|
LoginOrEmail string
|
|
|
|
|
|
|
|
Result *ExternalUserInfo
|
|
|
|
}
|
|
|
|
|
2018-02-08 16:13:58 -06:00
|
|
|
type GetAuthInfoQuery struct {
|
2019-02-01 18:40:57 -06:00
|
|
|
UserId int64
|
2018-02-08 16:13:58 -06:00
|
|
|
AuthModule string
|
|
|
|
AuthId string
|
|
|
|
|
2018-03-28 17:06:22 -05:00
|
|
|
Result *UserAuth
|
2018-02-08 16:13:58 -06:00
|
|
|
}
|
2018-07-01 09:01:43 -05:00
|
|
|
|
2022-11-29 08:20:28 -06:00
|
|
|
type GetUserLabelsQuery struct {
|
|
|
|
UserIDs []int64
|
|
|
|
}
|
|
|
|
|
2019-09-08 05:48:47 -05:00
|
|
|
type TeamOrgGroupDTO struct {
|
|
|
|
TeamName string `json:"teamName"`
|
|
|
|
OrgName string `json:"orgName"`
|
|
|
|
GroupDN string `json:"groupDN"`
|
|
|
|
}
|