2017-02-15 19:06:19 +01:00
|
|
|
package sessions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/context"
|
2019-07-23 16:47:28 +02:00
|
|
|
|
2020-05-28 15:20:58 +02:00
|
|
|
"github.com/google/uuid"
|
2017-02-15 19:06:19 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DefaultCookieName the secret cookie's name for sessions
|
|
|
|
DefaultCookieName = "irissessionid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2017-12-24 05:24:45 +01:00
|
|
|
// Config is the configuration for sessions. Please read it before using sessions.
|
2017-02-15 19:06:19 +01:00
|
|
|
Config struct {
|
|
|
|
// Cookie string, the session's client cookie name, for example: "mysessionid"
|
|
|
|
//
|
2017-10-01 03:31:13 +02:00
|
|
|
// Defaults to "irissessionid".
|
2017-02-15 19:06:19 +01:00
|
|
|
Cookie string
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// CookieSecureTLS set to true if server is running over TLS
|
2019-06-07 20:07:08 +02:00
|
|
|
// and you need the session's cookie "Secure" field to be set true.
|
2017-10-01 03:31:13 +02:00
|
|
|
// Defaults to false.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
CookieSecureTLS bool
|
|
|
|
|
2017-12-13 13:37:02 +01:00
|
|
|
// AllowReclaim will allow to
|
|
|
|
// Destroy and Start a session in the same request handler.
|
2017-12-15 14:46:18 +01:00
|
|
|
// All it does is that it removes the cookie for both `Request` and `ResponseWriter` while `Destroy`
|
|
|
|
// or add a new cookie to `Request` while `Start`.
|
2017-12-13 13:37:02 +01:00
|
|
|
//
|
|
|
|
// Defaults to false.
|
|
|
|
AllowReclaim bool
|
|
|
|
|
2020-05-09 13:04:51 +02:00
|
|
|
// Encoding should encodes and decodes
|
|
|
|
// authenticated and optionally encrypted cookie values.
|
2017-03-18 11:22:20 +01:00
|
|
|
//
|
2017-10-01 03:31:13 +02:00
|
|
|
// Defaults to nil.
|
2020-05-09 13:04:51 +02:00
|
|
|
Encoding context.SecureCookie
|
2017-10-01 03:31:13 +02:00
|
|
|
|
2017-02-15 19:06:19 +01:00
|
|
|
// Expires the duration of which the cookie must expires (created_time.Add(Expires)).
|
|
|
|
// If you want to delete the cookie when the browser closes, set it to -1.
|
|
|
|
//
|
|
|
|
// 0 means no expire, (24 years)
|
|
|
|
// -1 means when browser closes
|
|
|
|
// > 0 is the time.Duration which the session cookies should expire.
|
|
|
|
//
|
2017-10-01 03:31:13 +02:00
|
|
|
// Defaults to infinitive/unlimited life duration(0).
|
2017-02-15 19:06:19 +01:00
|
|
|
Expires time.Duration
|
|
|
|
|
2019-07-23 16:47:28 +02:00
|
|
|
// SessionIDGenerator can be set to a function which
|
|
|
|
// return a unique session id.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// By default we will use a uuid impl package to generate
|
|
|
|
// that, but developers can change that with simple assignment.
|
2020-07-10 22:21:09 +02:00
|
|
|
SessionIDGenerator func(ctx *context.Context) string
|
2017-02-15 19:06:19 +01:00
|
|
|
|
2017-07-10 17:32:42 +02:00
|
|
|
// DisableSubdomainPersistence set it to true in order dissallow your subdomains to have access to the session cookie
|
2017-02-15 19:06:19 +01:00
|
|
|
//
|
2017-10-01 03:31:13 +02:00
|
|
|
// Defaults to false.
|
2017-02-15 19:06:19 +01:00
|
|
|
DisableSubdomainPersistence bool
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Validate corrects missing fields configuration fields and returns the right configuration
|
|
|
|
func (c Config) Validate() Config {
|
|
|
|
if c.Cookie == "" {
|
|
|
|
c.Cookie = DefaultCookieName
|
|
|
|
}
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
if c.SessionIDGenerator == nil {
|
2020-07-10 22:21:09 +02:00
|
|
|
c.SessionIDGenerator = func(*context.Context) string {
|
2020-05-28 15:20:58 +02:00
|
|
|
id, _ := uuid.NewRandom()
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
return id.String()
|
|
|
|
}
|
2017-02-15 19:06:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|