oauth.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "net/http"
  4. oauth "imuslab.com/arozos/mod/auth/oauth2"
  5. prout "imuslab.com/arozos/mod/prouter"
  6. )
  7. func OAuthInit() {
  8. oAuthHandler := oauth.NewOauthHandler(authAgent, registerHandler, sysdb)
  9. adminRouter := prout.NewModuleRouter(prout.RouterOption{
  10. ModuleName: "System Setting",
  11. AdminOnly: true,
  12. UserHandler: userHandler,
  13. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  14. errorHandlePermissionDenied(w, r)
  15. },
  16. })
  17. // Public endpoints (called before the user is authenticated)
  18. http.HandleFunc("/system/auth/oauth/login", oAuthHandler.HandleLogin)
  19. http.HandleFunc("/system/auth/oauth/authorize", oAuthHandler.HandleAuthorize)
  20. http.HandleFunc("/system/auth/oauth/checkoauth", oAuthHandler.CheckOAuth)
  21. // Admin-only configuration endpoints
  22. adminRouter.HandleFunc("/system/auth/oauth/config/read", oAuthHandler.ReadConfig)
  23. adminRouter.HandleFunc("/system/auth/oauth/config/write", oAuthHandler.WriteConfig)
  24. adminRouter.HandleFunc("/system/auth/oauth/config/discover", oAuthHandler.HandleDiscover)
  25. registerSetting(settingModule{
  26. Name: "OAuth",
  27. Desc: "Sign in with any OIDC-compatible identity provider",
  28. IconPath: "SystemAO/advance/img/small_icon.png",
  29. Group: "Security",
  30. StartDir: "SystemAO/advance/oauth.html",
  31. RequireAdmin: true,
  32. })
  33. }