9 "github.com/bitly/oauth2_proxy/cookie"
12type SessionState struct {
20func (s *SessionState) IsExpired() bool {
21 if !s.ExpiresOn.IsZero() && s.ExpiresOn.Before(time.Now()) {
27func (s *SessionState) String() string {
28 o := fmt.Sprintf("Session{%s", s.userOrEmail())
29 if s.AccessToken != "" {
32 if !s.ExpiresOn.IsZero() {
33 o += fmt.Sprintf(" expires:%s", s.ExpiresOn)
35 if s.RefreshToken != "" {
36 o += " refresh_token:true"
41func (s *SessionState) EncodeSessionState(c *cookie.Cipher) (string, error) {
42 if c == nil || s.AccessToken == "" {
43 return s.userOrEmail(), nil
45 return s.EncryptedString(c)
48func (s *SessionState) userOrEmail() string {
56func (s *SessionState) EncryptedString(c *cookie.Cipher) (string, error) {
59 panic("error. missing cipher")
75 return fmt.Sprintf("%s|%s|%d|%s", s.userOrEmail(), a, s.ExpiresOn.Unix(), r), nil
78func DecodeSessionState(v string, c *cookie.Cipher) (s *SessionState, err error) {
79 chunks := strings.Split(v, "|")
81 if strings.Contains(chunks[0], "@") {
82 u := strings.Split(v, "@")[0]
83 return &SessionState{Email: v, User: u}, nil
85 return &SessionState{User: v}, nil
89 err = fmt.Errorf("invalid number of fields (got %d expected 4)", len(chunks))
94 if c != nil && chunks[1] != "" {
95 s.AccessToken, err = c.Decrypt(chunks[1])
100 if c != nil && chunks[3] != "" {
101 s.RefreshToken, err = c.Decrypt(chunks[3])
106 if u := chunks[0]; strings.Contains(u, "@") {
108 s.User = strings.Split(u, "@")[0]
112 ts, _ := strconv.Atoi(chunks[2])
113 s.ExpiresOn = time.Unix(int64(ts), 0)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list