Skip to content

Commit

Permalink
clean up of redudant cookie stuf
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbITCybErSeC committed Oct 11, 2024
1 parent 44b9b1b commit 36c5fbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 101 deletions.
104 changes: 4 additions & 100 deletions auth/cookies/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ const (
Token
)

// type ICookieJar interface {
// SetCallBackNonce(context *gin.Context, stateValue string) error
// SetCallBackState(context *gin.Context, stateValue string) error
// GetStateSession(context *gin.Context) (value string, isNew bool)
// GetNonceSession(context *gin.Context) (value string, isNew bool)
// GetUserToken(context *gin.Context) (value string, isNew bool)
// SetUserToken(context *gin.Context, token string) error
// DeleteStateSession(context *gin.Context) error
// DeleteNonceSession(context *gin.Context) error
// }
type Cookie struct {
CookieType CookieType
Value string
Expand Down Expand Up @@ -68,6 +58,10 @@ func NewCookie(cookieType CookieType, value string) (Cookie, error) {
}, nil
}

func NewCookieJar(secret []byte, encryptionKey []byte) *CookieJar {
return &CookieJar{store: sessions.NewCookieStore(secret, encryptionKey)}
}

func (cj *CookieJar) Delete(gc *gin.Context, cookieType CookieType) error {
var sessionName string
var keyName string
Expand Down Expand Up @@ -168,93 +162,3 @@ func (cj *CookieJar) Get(gc *gin.Context, cookieType CookieType) (value string,

return value, false, nil
}

func NewCookieJar(secret []byte, encryptionKey []byte) *CookieJar {
return &CookieJar{store: sessions.NewCookieStore(secret, encryptionKey)}
}

// func (cj *CookieJar) SetCallBackState(context *gin.Context, stateValue string) error {
// return cj.setCallBackSession(context, CALLBACK_STATE, stateValue)
// }
//
// func (cj *CookieJar) SetCallBackNonce(context *gin.Context, stateValue string) error {
// return cj.setCallBackSession(context, CALLBACK_NONCE, stateValue)
// }
//
// func (cj *CookieJar) GetStateSession(context *gin.Context) (value string, isNew bool) {
// return cj.getState(context, CALLBACK_STATE)
// }
//
// func (cj *CookieJar) GetNonceSession(context *gin.Context) (value string, isNew bool) {
// return cj.getState(context, CALLBACK_NONCE)
// }
//
// func (cj *CookieJar) GetUserToken(context *gin.Context) (value string, isNew bool) {
// return cj.getToken(context, USER_TOKEN)
// }
//
// func (cj *CookieJar) SetUserToken(context *gin.Context, token string) error {
// session, err := cj.store.Get(context.Request, USER_TOKEN)
// if err != nil {
// return err
// }
//
// session.Values["token"] = token
// session.Options.MaxAge = 60 * 60 * 8
// session.Options.Path = "/"
// session.Options.Secure = context.Request.TLS != nil
// session.Options.SameSite = http.SameSiteLaxMode
// return session.Save(context.Request, context.Writer)
// }
//
// func (cj *CookieJar) DeleteStateSession(context *gin.Context) error {
// return cj.deleteSession(context, CALLBACK_STATE)
// }
//
// func (cj *CookieJar) DeleteNonceSession(context *gin.Context) error {
// return cj.deleteSession(context, CALLBACK_NONCE)
// }
//
// func (cj *CookieJar) setCallBackSession(context *gin.Context, name string, stateValue string) error {
// session, err := cj.store.Get(context.Request, name)
// if err != nil {
// return err
// }
// session.Values["state"] = stateValue
// session.Options.MaxAge = 60 * 5
// session.Options.Path = "/"
// session.Options.Secure = context.Request.TLS != nil
// session.Options.SameSite = http.SameSiteLaxMode
// return session.Save(context.Request, context.Writer)
// }
//
// func (cj *CookieJar) getState(context *gin.Context, name string) (value string, isNew bool) {
// session, _ := cj.store.Get(context.Request, name)
// if session.IsNew {
// return "", true
// }
// value, ok := session.Values["state"].(string)
// if !ok {
// return "", true
// }
// return value, false
// }
//
// func (cj *CookieJar) getToken(context *gin.Context, name string) (value string, isNew bool) {
// session, _ := cj.store.Get(context.Request, name)
// if session.IsNew {
// return "", true
// }
// value, ok := session.Values["token"].(string)
// if !ok {
// return "", true
// }
// return value, false
// }
//
// func (cj *CookieJar) deleteSession(gc *gin.Context, name string) error {
// session, _ := cj.store.Get(gc.Request, name)
//
// session.Options.MaxAge = -1
// return session.Save(gc.Request, gc.Writer)
// }
2 changes: 1 addition & 1 deletion auth/gin_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (auth *Authenticator) OIDCCallBack(gc *gin.Context) {
}
tokenCookie, err := cookies.NewCookie(cookies.Token, accessToken)
if err != nil {
api.jsonerrorstat(gc, http.StatusInternalServerError, errors.new("failed to set access cookie token"))
api.JSONErrorStatus(gc, http.StatusInternalServerError, errors.New("failed to set access cookie token"))
return
}
auth.Cookiejar.Store(gc, tokenCookie)
Expand Down

0 comments on commit 36c5fbc

Please sign in to comment.