github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/auth/user.go (about) 1 package auth 2 3 import ( 4 "net/http" 5 ) 6 7 // User describes an Evergreen user and is returned by a UserManager. 8 type User interface { 9 DisplayName() string 10 Email() string 11 Username() string 12 } 13 14 // User describes an Evergreen user that is going through the API. 15 type APIUser interface { 16 User 17 GetAPIKey() string 18 } 19 20 // UserManager sets and gets user tokens for implemented authentication mechanisms, 21 // and provides the data that is sent by the api and ui server after authenticating 22 type UserManager interface { 23 GetUserByToken(token string) (User, error) 24 CreateUserToken(username, password string) (string, error) 25 // GetLoginHandler returns the function that starts the login process for auth mechanisms 26 // that redirect to a thirdparty site for authentication 27 GetLoginHandler(url string) func(http.ResponseWriter, *http.Request) 28 // GetLoginRedirectHandler returns the function that does login for the 29 // user once it has been redirected from a thirdparty site. 30 GetLoginCallbackHandler() func(http.ResponseWriter, *http.Request) 31 // IsRedirect returns true if the user must be redirected to a thirdparty site to authenticate 32 IsRedirect() bool 33 } 34 35 type simpleUser struct { 36 UserId string 37 Name string 38 EmailAddress string 39 } 40 41 func (u *simpleUser) DisplayName() string { 42 return u.Name 43 } 44 45 func (u *simpleUser) Email() string { 46 return u.EmailAddress 47 } 48 49 func (u *simpleUser) Username() string { 50 return u.UserId 51 }