Skip to content

Commit

Permalink
core: use deepcopy not gob encoding - closes ory#191
Browse files Browse the repository at this point in the history
  • Loading branch information
budougumi0617 committed Jul 8, 2017
1 parent 8bcb6c6 commit 3de2033
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
34 changes: 22 additions & 12 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions handler/oauth2/strategy_jwt_session.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package oauth2

import (
"bytes"
"encoding/gob"
"time"

"github.com/ory/fosite"
"github.com/ory/fosite/token/jwt"
"github.com/mohae/deepcopy"
)

type JWTSessionContainer interface {
Expand Down Expand Up @@ -80,11 +79,5 @@ func (s *JWTSession) Clone() fosite.Session {
return nil
}

var clone JWTSession
var mod bytes.Buffer
enc := gob.NewEncoder(&mod)
dec := gob.NewDecoder(&mod)
_ = enc.Encode(s)
_ = dec.Decode(&clone)
return &clone
return deepcopy.Copy(s).(fosite.Session)
}
12 changes: 2 additions & 10 deletions handler/openid/strategy_jwt.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package openid

import (
"encoding/gob"
"time"

"bytes"
"context"

"github.com/ory/fosite"
"github.com/ory/fosite/token/jwt"
"github.com/pkg/errors"
"github.com/mohae/deepcopy"
)

const defaultExpiryTime = time.Hour
Expand Down Expand Up @@ -42,13 +40,7 @@ func (s *DefaultSession) Clone() fosite.Session {
return nil
}

var clone DefaultSession
var mod bytes.Buffer
enc := gob.NewEncoder(&mod)
dec := gob.NewDecoder(&mod)
_ = enc.Encode(s)
_ = dec.Decode(&clone)
return &clone
return deepcopy.Copy(s).(fosite.Session)
}

func (s *DefaultSession) SetExpiresAt(key fosite.TokenType, exp time.Time) {
Expand Down
11 changes: 2 additions & 9 deletions session.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package fosite

import (
"bytes"
"encoding/gob"
"time"
"github.com/mohae/deepcopy"
)

// Session is an interface that is used to store session data between OAuth2 requests. It can be used to look up
Expand Down Expand Up @@ -74,11 +73,5 @@ func (s *DefaultSession) Clone() Session {
return nil
}

var clone DefaultSession
var mod bytes.Buffer
enc := gob.NewEncoder(&mod)
dec := gob.NewDecoder(&mod)
_ = enc.Encode(s)
_ = dec.Decode(&clone)
return &clone
return deepcopy.Copy(s).(Session)
}

0 comments on commit 3de2033

Please sign in to comment.