Comments (4)
Thank you very much!
from iris.
I tested the below, which is identical to your use case and works as expected, please make good post issues I don't have the necessary info to help you... try to find out what your rest application does and fails on you
app := iris.New()
cookieName := "mycustomsessionid"
// AES only supports key sizes of 16, 24 or 32 bytes.
// You either need to provide exactly that amount or you derive the key from what you type in.
hashKey := []byte("the-big-and-secret-fash-key-here")
blockKey := []byte("lot-secret-of-characters-big-too")
secureCookie := securecookie.New(hashKey, blockKey)
mySessions := sessions.New(sessions.Config{
Cookie: cookieName,
Encode: secureCookie.Encode,
Decode: secureCookie.Decode,
Expires: time.Hour * 1,
})
app.Post("/set_boolean", func(ctx context.Context) {
s := mySessions.Start(ctx)
s.Set("authenticated", true)
s.Set("UserId", "42")
ctx.Redirect("/get_boolean")
})
app.Get("/get_boolean", func(ctx context.Context) {
s := mySessions.Start(ctx)
auth, err := s.GetBoolean("authenticated")
if !auth || err != nil {
ctx.Writef("expected authenticated to be true!\n")
}
if userid := s.Get("UserId"); userid != "42" {
ctx.Writef("expected UserId to be 42!")
}
})
from iris.
I found why it doesn't work, that's cause the browser cookie in response. The cookie is sent with empty value:
It should be like this:
from iris.
The problem is your hashKey, the length is too short, it must be 32 ou 68 octets. That's why, the cookie name is empty.
As it say in SecureCookie documentation:
// hashKey is required, used to authenticate values using HMAC. Create it using
// GenerateRandomKey(). It is recommended to use a key with 32 or 64 bytes.
//
// blockKey is optional, used to encrypt values. Create it using
// GenerateRandomKey(). The key length must correspond to the block size
// of the encryption algorithm. For AES, used by default, valid lengths are
// 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
// The default encoder used for cookie serialization is encoding/gob.
from iris.
Related Issues (20)
- [BUG] The cache entry has not been truly deleted after expiration HOT 5
- [BUG] Pluralization uses yml for template configuration, uses ctx.Tr method for rendering, returns no data HOT 1
- [BUG] HOT 3
- [BUG] may be an out-of-boundary bug as a result of lack of necessary argument checks HOT 1
- [BUG] Process hang HOT 1
- [FEATURE REQUEST] redis sentinel support
- [FEATURE REQUEST] Support log/slog HOT 4
- [QUESTION] iris v12.2.0 app.ContextPool.Attach not found HOT 1
- [HELP] How to dynamically start http services on multiple ports? HOT 1
- [HELP] How to proactively send websocket messages to the client in an MVC structure?
- [HELP] Multiple event when using native message
- Iris gRPC wrapper breaking HOT 1
- getBuiltinFuncs problem
- [BUG] template part Unable to load HOT 1
- [BUG] I used goroutine to affect the later HTTP before the service startup HOT 2
- [BUG] validation of binding is not effective
- [QUESTION] The session configuration provided by the iris framework is limited
- [FEATURE REQUEST] Get the data in the session through the session id
- [BUG] ctx.RemoveCookie need more special attribute(`domain` and `path`) value to remove cookies HOT 3
- slog is not in GOROOT HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iris.