oauth2-authorize-server/cmd/api/routes.go

38 lines
1.3 KiB
Go

package main
import (
"expvar"
"net/http"
"github.com/julienschmidt/httprouter"
)
func (app *application) routes() http.Handler {
router := httprouter.New()
router.NotFound = http.HandlerFunc(app.notFoundResponse)
router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowResponse)
router.HandlerFunc(http.MethodGet, "/v1/healthcheck", app.healthcheckHandler)
// 授权
router.HandlerFunc(http.MethodGet, "/v1/oauth2/authorize", app.authorizeHandler)
router.HandlerFunc(http.MethodPost, "/v1/oauth2/authorize", app.authorizeHandler)
router.HandlerFunc(http.MethodGet, "/v1/oauth2/login", app.loginHandler)
router.HandlerFunc(http.MethodPost, "/v1/oauth2/login", app.loginHandler)
router.HandlerFunc(http.MethodGet, "/v1/oauth2/token", app.tokenHandler)
router.HandlerFunc(http.MethodPost, "/v1/oauth2/token", app.tokenHandler)
router.HandlerFunc(http.MethodGet, "/v1/oauth2/agree-auth", app.agreeAuthHandler)
router.HandlerFunc(http.MethodGet, "/v1/oauth2/get-user-info", app.getUserInfoHandler)
router.ServeFiles("/auth/*filepath", http.Dir("./internal/static"))
router.Handler(http.MethodGet, "/debug/vars", expvar.Handler())
return app.metrics(
app.recoverPanic(
app.enableCORS(
app.rateLimit(
app.authenticate(router),
),
),
),
)
}