summaryrefslogtreecommitdiff
path: root/pkg/x/session.go
blob: 830c4df243b854b2629421e8db93d44c1e99fc6c (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
package x

import (
	"net/http"

	"github.com/coreos/go-oidc/v3/oidc"
	"golang.org/x/oauth2"
)

type Session struct {
	Token             *oauth2.Token
	IdToken           *oidc.IDToken
	IdTokenRaw        interface{}
	Profile           map[string]interface{}
	AccessTokenClaims map[string]interface{}
	Message           string
	OAuthState        string
}

func (s *Session) IsLoggedIn() bool {
	return s.Token != nil
}

func (s *Session) Flash(msg string, w http.ResponseWriter, r *http.Request) {
	s.Message = msg
	http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}

func (s *Session) Reset() {
	s.Token = nil
	s.IdToken = nil
	s.IdTokenRaw = nil
	s.Profile = map[string]interface{}{}
	s.AccessTokenClaims = map[string]interface{}{}
	s.Message = ""
	s.OAuthState = ""
}