2022-11-12 13:34:39 -05:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
2022-11-12 15:56:17 -05:00
|
|
|
type UserID string
|
|
|
|
type GroupID string
|
|
|
|
type CredID string
|
2022-11-12 13:34:39 -05:00
|
|
|
|
|
|
|
type User struct {
|
2022-11-12 17:42:51 -05:00
|
|
|
ID UserID `json:"id"`
|
|
|
|
GroupIDs []GroupID `json:"group_ids"`
|
|
|
|
Data interface{} `json:"data,omitempty"`
|
2022-11-12 13:34:39 -05:00
|
|
|
UserMetadata
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserMetadata struct {
|
2022-11-12 17:42:51 -05:00
|
|
|
Active bool `json:"is_active"`
|
|
|
|
Owner bool `json:"is_owner"`
|
|
|
|
LocalOnly bool `json:"local_only"`
|
|
|
|
SystemGenerated bool `json:"system_generated"`
|
|
|
|
Name string `json:"name"`
|
2022-11-12 13:34:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (u *User) allowedToAuth() error {
|
|
|
|
if !u.Active {
|
|
|
|
return errors.New("user disabled")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Authenticator) getOrCreateUser(c *Credential) (*User, error) {
|
2022-11-12 15:56:17 -05:00
|
|
|
log.Debug().Interface("userdata", c.user.ProviderUserData()).Msg("getOrCreateUser")
|
2022-11-12 17:50:01 -05:00
|
|
|
u := a.store.User(c.UserID)
|
|
|
|
if u == nil {
|
|
|
|
return nil, errors.New("no such user)
|
|
|
|
}
|
|
|
|
|
|
|
|
return u, nil
|
2022-11-12 13:34:39 -05:00
|
|
|
}
|