auth.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Public Domain Software
  3. *
  4. * I (Matthias Ladkau) am the author of the source code in this file.
  5. * I have placed the source code in this file in the public domain.
  6. *
  7. * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. /*
  10. Package auth contains user authentication code for webservers.
  11. Basic access authentication requires a client to provide a user name and password
  12. with each request. Most browsers will directly support this method.
  13. See: https://en.wikipedia.org/wiki/Basic_access_authentication
  14. Cookie based authentication requires the client to login once and create a unique
  15. access token. The access token is then used to authenticate each request.
  16. */
  17. package auth
  18. import "net/http"
  19. /*
  20. HandleFuncWrapper is an abstract wrapper for handle functions to add authentication features.
  21. */
  22. type HandleFuncWrapper interface {
  23. /*
  24. SetAuthFunc gives an authentication function which can be used by the
  25. wrapper to authenticate users.
  26. */
  27. SetAuthFunc(authFunc func(user, pass string) bool)
  28. /*
  29. HandleFunc is the new handle func which wraps an original handle functions to do an authentication check.
  30. */
  31. HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
  32. /*
  33. CheckAuth checks the user authentication of an incomming request. Returns
  34. if the authentication is correct and the given username.
  35. */
  36. CheckAuth(r *http.Request) (string, bool)
  37. }