Brijesh's Git Server — identity @ 8c36e39b8c6eda064ffa45901a976c3ebf028d97

authentication service

core/internal/server/routes.go (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
package server

import (
	"net/http"

	"github.com/go-chi/chi/v5"
	chiMiddleware "github.com/go-chi/chi/v5/middleware"

	"github.com/wbrijesh/identity/internal/middleware"
)

func (s *Server) RegisterRoutes() http.Handler {
	r := chi.NewRouter()
	r.Use(chiMiddleware.Logger)

	r.Get("/health", s.healthHandler)

	// Admin routes
	r.Post("/admin/register", s.CreateAdminHandler)
	r.Post("/admin/login", s.LoginAdminHandler)

	// Application routes (protected by Admin auth middleware)
	r.Group(func(r chi.Router) {
		r.Use(middleware.AdminAuthMiddleware)

		r.Post("/applications", s.CreateApplicationHandler)
		r.Get("/applications", s.ListApplicationsHandler)
		r.Post("/applications/{applicationID}/refresh-token", s.GenerateRefreshTokenForApplicationHandler)
		r.Put("/applications/{applicationID}/refresh-token", s.UpdateRefreshTokenForApplicationHandler)
	})

	// User routes (protected by Access Token auth middleware)
	r.Group(func(r chi.Router) {
		r.Use(middleware.AcessTokenAuthMiddleware)

		r.Post("/users", s.CreateUserHandler)
		r.Post("/users/login", s.LoginUserHandler)
		r.Get("/applications/{applicationID}/users", s.ListUsersHandler)
	})

	return r
}