Skip to content

Commit

Permalink
Reuse the super secure session store for Drive! Fixes #36 ^_^
Browse files Browse the repository at this point in the history
  • Loading branch information
adayoung committed Apr 21, 2024
1 parent 9b4670c commit be010a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pastebin/models/gdrive.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ func init() {
gob.Register(&oauth2.Token{})
}

var sessionStore = sessions.NewCookieStore([]byte(os.Getenv("CSRFAuthKey")))

func SaveOAuthToken(w http.ResponseWriter, r *http.Request, token *oauth2.Token) error {
if session, err := sessionStore.Get(r, os.Getenv("CookiePrefix")+"_oauth2_gdrive"); err != nil {
if session, err := utils.SessionStore().Get(r, os.Getenv("CookiePrefix")+"_oauth2_gdrive"); err != nil {
return err
} else {
session.Options = &sessions.Options{
Expand All @@ -50,7 +48,7 @@ func SaveOAuthToken(w http.ResponseWriter, r *http.Request, token *oauth2.Token)
}

func GetOAuthToken(r *http.Request) (*oauth2.Token, error) {
if session, err := sessionStore.Get(r, os.Getenv("CookiePrefix")+"_oauth2_gdrive"); err != nil {
if session, err := utils.SessionStore().Get(r, os.Getenv("CookiePrefix")+"_oauth2_gdrive"); err != nil {
return nil, err
} else {
if token, ok := session.Values["gdrive"].(*oauth2.Token); ok {
Expand Down
4 changes: 4 additions & 0 deletions pastebin/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func sessionStore() *sessions.CookieStore {
return ss
}

func SessionStore() *sessions.CookieStore {
return sessionStore()
}

func UpdateSession(w http.ResponseWriter, r *http.Request, paste_id string, remove bool) error {
if session, err := sessionStore().Get(r, os.Getenv("CookiePrefix")+"_pb_session"); err != nil {
return err
Expand Down

0 comments on commit be010a0

Please sign in to comment.