// User represents a user returned from AuthenticatorService
typeUserstruct{
typeUserstruct{
Usernamestring`json:"username"`
Usernamestring`json:"username"`
Namestring`json:"name"`
Namestring`json:"name"`
@ -12,6 +14,7 @@ type User struct {
Emailstring`json:"email"`
Emailstring`json:"email"`
}
}
// WithDefaultFullName is a utility that returns a copy of the given user with the full name set to the concatenation of the name and surname of the user.
func(uUser)WithDefaultFullName()User{
func(uUser)WithDefaultFullName()User{
returnUser{
returnUser{
Username:u.Username,
Username:u.Username,
@ -23,18 +26,28 @@ func (u User) WithDefaultFullName() User {
}
}
}
}
// Session represents a session returned from AuthenticatorService
typeSessionstruct{
typeSessionstruct{
Usernamestring`json:"username"`
Usernamestring`json:"username"`
Tokenstring`json:"token"`
Tokenstring`json:"token"`
}
}
// AuthenticatorService can login users using a separate http service or a temporary in memory store. When a user logs in the auth service returns a session token that can be used to read and modify user properties without having to re-send the user password. (TODO: Not yet implemented: this token has to be renewed every so often otherwise it lasts just a couple of days)
typeAuthenticatorServiceinterface{
typeAuthenticatorServiceinterface{
// GetUser retrieves the user info given the username
GetUser(usernamestring)(*User,error)
GetUser(usernamestring)(*User,error)
// GetUsers retrieves the full user list from the authentication service
GetUsers()([]*User,error)
GetUsers()([]*User,error)
// GetSession retrieves the user session associated to a session token
GetSession(tokenstring)(*Session,error)
GetSession(tokenstring)(*Session,error)
// Login tries to log in a user given username and password and if successful returns a new user session
Login(username,passwordstring)(*Session,error)
Login(username,passwordstring)(*Session,error)
}
}
// UserForSession returns the user (object) linked to a session token, this is just a shortcut for calling [AuthenticatorService.GetSession] and then [AuthenticatorService.GetUser]
// New create an AuthenticatorService given an "host" string, if ":memory:" then this just returns an example AuthenticatorService using the [auth.Memory] implementation, otherwise for now this defaults to [auth.LDAPAuthService]