summaryrefslogtreecommitdiff
path: root/pkg/web/http_context.go
blob: 16742c7d3abb70ed4d0722391ac680ecda90353b (plain)
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
package web

import (
	"log"
	"net/http"
)

type HttpContext struct {
	issuer  string
	keyData []byte
	log     *log.Logger
}

func NewHttpContext(issuer string, keyData []byte) *HttpContext {
	return &HttpContext{
		issuer:  issuer,
		keyData: keyData,
		log:     log.Default(),
	}
}

func (h *HttpContext) Router() *http.ServeMux {
	mux := http.NewServeMux()

	mux.Handle("/", http.HandlerFunc(h.Default))
	mux.Handle("/.well-known/", h.wellKnownMux())
	mux.Handle("/authorize", http.HandlerFunc(h.Authorize))
	mux.Handle("/register", http.HandlerFunc(h.Register))
	mux.Handle("/revoke", http.HandlerFunc(http.NotFound))
	mux.Handle("/token", http.HandlerFunc(h.Token))
	mux.Handle("/userinfo", http.HandlerFunc(http.NotFound))
	return mux
}

func (h *HttpContext) wellKnownMux() *http.ServeMux {
	mux := http.NewServeMux()
	mux.Handle("/.well-known/jwks.json", http.HandlerFunc(h.JsonWebKeySets))
	mux.Handle("/.well-known/openid-configuration", http.HandlerFunc(h.OpenIdConfiguration))
	return mux
}