@@ -9,6 +9,7 @@ import (
99 "github.com/pusher/oauth2_proxy/cookie"
1010)
1111
12+// SessionState is used to store information about the currently authenticated user session
1213type SessionState struct {
1314 AccessToken string
1415 ExpiresOn time.Time
@@ -17,6 +18,7 @@ type SessionState struct {
1718 User string
1819}
1920
21+// IsExpired checks whether the session has expired
2022func (s *SessionState) IsExpired() bool {
2123 if !s.ExpiresOn.IsZero() && s.ExpiresOn.Before(time.Now()) {
2224 return true
@@ -24,6 +26,7 @@ func (s *SessionState) IsExpired() bool {
2426 return false
2527}
2628
29+// String constructs a summary of the session state
2730func (s *SessionState) String() string {
2831 o := fmt.Sprintf("Session{%s", s.accountInfo())
2932 if s.AccessToken != "" {
@@ -38,6 +41,7 @@ func (s *SessionState) String() string {
3841 return o + "}"
3942}
4043
44+// EncodeSessionState returns string representation of the current session
4145func (s *SessionState) EncodeSessionState(c *cookie.Cipher) (string, error) {
4246 if c == nil || s.AccessToken == "" {
4347 return s.accountInfo(), nil
@@ -49,6 +53,7 @@ func (s *SessionState) accountInfo() string {
4953 return fmt.Sprintf("email:%s user:%s", s.Email, s.User)
5054}
5155
56+// EncryptedString encrypts the session state into a cookie string
5257func (s *SessionState) EncryptedString(c *cookie.Cipher) (string, error) {
5358 var err error
5459 if c == nil {
@@ -84,6 +89,7 @@ func decodeSessionStatePlain(v string) (s *SessionState, err error) {
8489 return &SessionState{User: user, Email: email}, nil
8590}
8691
92+// DecodeSessionState decodes the session cookie string into a SessionState
8793func DecodeSessionState(v string, c *cookie.Cipher) (s *SessionState, err error) {
8894 if c == nil {
8995 return decodeSessionStatePlain(v)