Giter Site home page Giter Site logo

abraithwaite / jeff Goto Github PK

View Code? Open in Web Editor NEW
263.0 6.0 17.0 81 KB

🍍Jeff provides the simplest way to manage web sessions in Go.

License: BSD 3-Clause "New" or "Revised" License

Go 96.80% Makefile 2.74% Dockerfile 0.45%
golang sessions http session-management web-framework go web-sessions cookie csrf-protection middleware

jeff's Issues

Comparison to github.com/alexedwards/scs

A quick look at both libraries seems to show an important difference: github.com/alexedwards/scs buffers all response bytes. A bufferedResponseWriter{} buffering all output to catch session changes before headers are sent (

Jeff seems to handle this better (but not easier) by making you call Set manually when headers should be set without wrapping your http.Handler.

Don't use alexedwards/scs if you send large payloads to clients, stream response bodies, use websockets(?), etc.

Evaluate using gokv as storage interface

Hi, I saw your project in my GitHub feed because someone I follow starred it and when seeing the Storage interface I immediately thought that it would be a great fit for a project of mine: https://github.com/philippgille/gokv

I'll paste the code here so you don't have to follow the links:

jeff.Storage:

type Storage interface {
	Store(ctx context.Context, key, value []byte, exp time.Time)
	Fetch(ctx context.Context, key []byte) (value []byte, err error)
	Delete(ctx context.Context, key []byte) error
}

gokv.Store:

type Store interface {
    Set(k string, v interface{}) error
    Get(k string, v interface{}) (found bool, err error)
    Delete(k string) error
    Close() error
}

Downsides:

  • gokv doesn't work with contexts yet
  • There's no expiration handling in the implementations, but you can save the whole item (that includes the expiration) and similarly to your memory implementation (here), just not return it when it's expired.

Upsides:

  • The main upside is the number of implementations for the interface. There's a simple Go map, sync.Map, FreeCache, BigCache, bbolt (a.k.a. BoltDB), BadgerDB, LevelDB, Local files, Redis, Consul, etcd, Apache ZooKeeper, Memcached, Hazelcast, Amazon DynamoDB, Amazon S3, Azure Table Storage, Google Cloud Datastore, Alibaba Cloud Tablestore, MySQL, PostgreSQL, MongoDB, CockroachDB and Apache Ignite. And more to come :)
  • All implementations allow to save any struct instead of just a slice of bytes. That's useful for example to include the expiration when storing a session and allows extending the stored struct with more fields in the future

This is exactly the use case that I had in mind when creating it: As a package creator you want your package users to to be able to use as many storage implementations as possible, so you only use a common key-value interface and then point package users to existing implementations.

Maybe you can have a look at it and then I'd love to hear what you think :)

Multiple sessions per key

Currently, each session requires a unique key. Would be nicer if we stored a list of sessions for each key.

Session Metadata

Provide ability to store generic session metadata with session (binary blob).

No way to delete a single session for a given user

Currently, user's sessions are stored as a list of active sessions under a single key in redis, each with their own unique token.

When we moved to this model, we didn't update the Clear and Delete methods to be able to clear just an individual session. As it stands, calling either of these methods will terminate all active sessions instead of just one, as it was originally intended.

Can I replace authboss with yours?

Excuse the question maybe very basic for you, but I'm learning day by day and I want to understand well.

I am using authboss for a hobby project.

But I do not need most of its features: I would just like to authenticate a user (email and password) if he has to use specific APIs.

Do you think I can replace authboss with your project?

Add control of SameSite prefix

For our application, we need our session cookies to have SameSite=None. SameSite=lax is hardcoded in the cookie setup, here:

w.Header().Set("Set-Cookie", w.Header().Get("Set-Cookie")+"; SameSite=lax")

Can SameSite's setting become an Option on jeff.New()?

sessions: load all sessions for user

Hi @abraithwaite!
First of all, I want to say thanks a lot for this package, I found out that popular packages were lacking for my use-case where I want to search sessions by user-id.

However, after taking a look around, I couldn't find an exported function to get all active sessions for a user.
This is helpful, for example, if the user is logged in from many devices and we want to revoke them all at once.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.