-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
50 lines (41 loc) · 1.35 KB
/
main.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
49
50
package main
import (
"github.com/gorilla/sessions"
lc "github.com/piensa/logico/logconsent"
"net/http"
)
var (
d *lc.Database
h *lc.Hydra
store = sessions.NewCookieStore([]byte("something-very-secret-keep-it-safe"))
)
const sessionName = "authentication"
func main() {
d = &lc.Database{
Dbuser: GetEnv("DB_USER", "dbuser"),
Dbpw: GetEnv("DB_PW", "secret"),
Dbname: GetEnv("DB_NAME", "testusers"),
Dbhost: GetEnv("DB_HOST", "localhost"),
Dbport: GetEnv("DB_PORT", "5433"),
}
d.Connect()
defer d.Db.Close()
port := GetEnv("PORT", "3000")
// url := "0.0.0.0:" + port
// Create hydra client.
hydraConfig := map[string]string{
"public_url": GetEnv("HYDRA_PUBLIC_URL", "http://api.logi.co"),
"admin_url": GetEnv("HYDRA_ADMIN_URL", "http://admin.logi.co"),
"client_id": GetEnv("HYDRA_CLIENT_ID", "piensa"),
"client_secret": GetEnv("HYDRA_CLIENT_SECRET", "piensa"),
"scopes": GetEnv("HYDRA_SCOPES", "openid,offline,eat,sleep,rave,repeat"),
"callback_url": GetEnv("CALLBACK_URL", "http://localhost:3000/callback"),
}
h = lc.CreateHydraClient(hydraConfig)
http.HandleFunc("/", homeHandler)
http.HandleFunc("/login", loginHandler)
http.HandleFunc("/consent", consentHandler)
http.HandleFunc("/callback", callbackHandler)
http.HandleFunc("/logout", logoutHandler)
http.ListenAndServe("0.0.0.0:"+port, nil)
}