oauth.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. http.HandleFunc("/system/auth/oauth/login", oAuthHandler.HandleLogin)
  18. http.HandleFunc("/system/auth/oauth/authorize", oAuthHandler.HandleAuthorize)
  19. http.HandleFunc("/system/auth/oauth/checkoauth", oAuthHandler.CheckOAuth)
  20. adminRouter.HandleFunc("/system/auth/oauth/config/read", oAuthHandler.ReadConfig)
  21. adminRouter.HandleFunc("/system/auth/oauth/config/write", oAuthHandler.WriteConfig)
  22. registerSetting(settingModule{
  23. Name: "OAuth",
  24. Desc: "Allows external account access to system",
  25. IconPath: "SystemAO/advance/img/small_icon.png",
  26. Group: "Security",
  27. StartDir: "SystemAO/advance/oauth.html",
  28. RequireAdmin: true,
  29. })
  30. }