-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.go
34 lines (26 loc) · 1.03 KB
/
router.go
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
package api
import (
"github.com/adrianosela/auth/keystore"
"github.com/adrianosela/auth/openid"
"github.com/adrianosela/auth/storage"
"github.com/gorilla/mux"
)
// Configuration includes the datastore, the keystore, and the identity provider
type Configuration struct {
DB storage.Datastore
Keystore keystore.Keystore
OpenID *openid.DiscoveryConfig
}
//GetRouter returns a router given an APIConfiguration
func GetRouter(conf *Configuration) *mux.Router {
router := mux.NewRouter()
// OpenID Connect Endpoints
router.Methods("GET").Path(openid.DefaultDiscoveryPath).HandlerFunc(conf.OpenID.HTTPHandlerFunc())
router.Methods("GET").Path("/auth/keys").HandlerFunc(conf.Keystore.SharePubKeyHandler)
// Basic Auth Endpoints --> Emitting JWT Tokens
router.Methods("GET").Path("/auth/login").HandlerFunc(conf.GetTokenHandler)
// Groups Mgmt Endpoints
router.Methods("GET").Path("/groups").HandlerFunc(conf.DB.ListGroupsHandler)
router.Methods("GET").Path("/groups/{group_id}").HandlerFunc(conf.DB.ShowGroupHandler)
return router
}