sessions: sign-out bug fixes #530 (#544)

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2020-03-19 18:43:43 -07:00 committed by GitHub
parent d5d180aa01
commit 4491d1b0e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
package sessions
import (
"encoding/json"
"errors"
"fmt"
"strings"
@ -182,3 +183,24 @@ func (s *State) accessTokenHash() string {
}
return fmt.Sprintf("%x", hash)
}
// UnmarshalJSON parses the JSON-encoded session state.
// TODO(BDD): remove in v0.8.0
func (s *State) UnmarshalJSON(b []byte) error {
type Alias State
t := &struct {
*Alias
OldToken *oauth2.Token `json:"access_token,omitempty"` // < v0.5.0
}{
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
if t.AccessToken == nil {
t.AccessToken = t.OldToken
}
*s = *(*State)(t.Alias)
return nil
}