user_auth.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package models
  2. import (
  3. "time"
  4. "golang.org/x/oauth2"
  5. )
  6. const (
  7. AuthModuleLDAP = "ldap"
  8. )
  9. type UserAuth struct {
  10. Id int64
  11. UserId int64
  12. AuthModule string
  13. AuthId string
  14. Created time.Time
  15. OAuthAccessToken string
  16. OAuthRefreshToken string
  17. OAuthTokenType string
  18. OAuthExpiry time.Time
  19. }
  20. type ExternalUserInfo struct {
  21. OAuthToken *oauth2.Token
  22. AuthModule string
  23. AuthId string
  24. UserId int64
  25. Email string
  26. Login string
  27. Name string
  28. Groups []string
  29. OrgRoles map[int64]RoleType
  30. IsGrafanaAdmin *bool // This is a pointer to know if we should sync this or not (nil = ignore sync)
  31. IsDisabled bool
  32. }
  33. // ---------------------
  34. // COMMANDS
  35. type UpsertUserCommand struct {
  36. ReqContext *ReqContext
  37. ExternalUser *ExternalUserInfo
  38. SignupAllowed bool
  39. Result *User
  40. }
  41. type SetAuthInfoCommand struct {
  42. AuthModule string
  43. AuthId string
  44. UserId int64
  45. OAuthToken *oauth2.Token
  46. }
  47. type UpdateAuthInfoCommand struct {
  48. AuthModule string
  49. AuthId string
  50. UserId int64
  51. OAuthToken *oauth2.Token
  52. }
  53. type DeleteAuthInfoCommand struct {
  54. UserAuth *UserAuth
  55. }
  56. // ----------------------
  57. // QUERIES
  58. type LoginUserQuery struct {
  59. ReqContext *ReqContext
  60. Username string
  61. Password string
  62. User *User
  63. IpAddress string
  64. }
  65. type GetUserByAuthInfoQuery struct {
  66. AuthModule string
  67. AuthId string
  68. UserId int64
  69. Email string
  70. Login string
  71. Result *User
  72. }
  73. type GetExternalUserInfoByLoginQuery struct {
  74. LoginOrEmail string
  75. Result *ExternalUserInfo
  76. }
  77. type GetAuthInfoQuery struct {
  78. UserId int64
  79. AuthModule string
  80. AuthId string
  81. Result *UserAuth
  82. }
  83. type TeamOrgGroupDTO struct {
  84. TeamName string `json:"teamName"`
  85. OrgName string `json:"orgName"`
  86. GroupDN string `json:"groupDN"`
  87. }
  88. type GetTeamsForLDAPGroupCommand struct {
  89. Groups []string
  90. Result []TeamOrgGroupDTO
  91. }
  92. type SyncTeamsCommand struct {
  93. ExternalUser *ExternalUserInfo
  94. User *User
  95. }