-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
48 lines (38 loc) · 1.26 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package router
import (
"encoding/gob"
"html/template"
"io/ioutil"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github.com/atori74/aws-oidc-login/platform/authenticator"
"github.com/atori74/aws-oidc-login/platform/options"
"github.com/atori74/aws-oidc-login/web/app/callback"
"github.com/atori74/aws-oidc-login/web/app/login"
)
// New registers the routes and returns the router.
func New(auth *authenticator.Authenticator, opts *options.Options, done chan interface{}) (*gin.Engine, error) {
gin.DefaultWriter = ioutil.Discard
router := gin.Default()
// To store custom types in our cookies,
// we must first register them using gob.Register
gob.Register(map[string]interface{}{})
store := cookie.NewStore([]byte("secret"))
router.Use(sessions.Sessions("auth-session", store))
t, err := loadTemplate("authenticated.html", callback.Template())
if err != nil {
return nil, err
}
router.SetHTMLTemplate(t)
router.GET("/login", login.Handler(auth))
router.GET("/callback", callback.Handler(auth, opts, done))
return router, nil
}
func loadTemplate(name, content string) (*template.Template, error) {
t, err := template.New(name).Parse(content)
if err != nil {
return nil, err
}
return t, nil
}