forked from Place1/wg-access-server
-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
runtime.go
45 lines (34 loc) · 1.22 KB
/
runtime.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
package authruntime
import (
"net/http"
"github.com/freifunkMUC/wg-access-server/pkg/authnz/authsession"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
)
type Provider struct {
Type string
Name string
Invoke func(http.ResponseWriter, *http.Request, *ProviderRuntime)
RegisterRoutes func(*mux.Router, *ProviderRuntime) error
}
type ProviderRuntime struct {
store sessions.Store
}
func NewProviderRuntime(store sessions.Store) *ProviderRuntime {
return &ProviderRuntime{store}
}
func (p *ProviderRuntime) SetSession(w http.ResponseWriter, r *http.Request, s *authsession.AuthSession) error {
return authsession.SetSession(p.store, r, w, s)
}
func (p *ProviderRuntime) GetSession(r *http.Request) (*authsession.AuthSession, error) {
return authsession.GetSession(p.store, r)
}
func (p *ProviderRuntime) ClearSession(w http.ResponseWriter, r *http.Request) error {
return authsession.ClearSession(p.store, r, w)
}
func (p *ProviderRuntime) Restart(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/signin?signout=1", http.StatusTemporaryRedirect)
}
func (p *ProviderRuntime) Done(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}