Code Monkey home page Code Monkey logo

ezauth's Introduction

Warning

This project is still in an experimental phase.

Goal

Make it trivial to add user auth to a Go HTTP app with complete HTML templates, using any *sql.DB compliant database as the storage mechanism.

Rolling one's own auth is a risk vector and a distraction from implementing business logic. Offloading auth onto an external provider is an additional cost, adds the latency of a network hop, and removes full control over one's application.

An importable package can solve these problems in minutes instead of hours, and this is what ezauth intends to do.

Sponsor

I will be creating this package over the next few weeks or months, but am currently bottlenecked by a full time job which consumes most my time, energy, and focus.

If sponsors could cover my monthly expenses, I could channel all my energy to making this the best it could be in a more timely manner.

This package could greatly benefit myself, indie developers, and enterprises alike.

Demo

ezauth-demo

Sample

func main() {
	mux := http.NewServeMux()
	cfg := ezauth.Config{
		DB: db,
		// override default templates
		// add configured oauth providers
		// ...
	}
	auth, err := ezauth.NewAuth(&cfg)
	auth.RegisterRoutes(mux)
	mux.Handle("/profile", auth.SessionMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		tmpl := template.Must(template.New("").ParseFiles("internal/profile.html"))
		tmpl.ExecuteTemplate(w, "profile.html", nil)
	})))
	fmt.Println("Listening on :8080")
	if err := http.ListenAndServe(":8080", mux); err != nil {
		panic(err)
	}
}

Motivation

Basic bcrypt auth isn't that hard to learn for a Go net/http web app. Its true, but online forums are littered with desparate cries for a django-allauth equivalent in the Go ecosystem, which doesn't exist (in a way that is trivial to incorporate). These cries either come from beginners, or from time conscious individuals uninterested in reinventing wheels. Both are valid.

The basic requirements are to handle the basic auth flows with email/pass (and probably OAuth), against a database/sql compliant database connection.

This compliance is important, because this means it should support different databases. SQLite and Postgres have their strengths, its nice to be able to choose.

Most importantly, it should be trivial to incorporate. Just import the package, add the route group, and instantly access premade HTML pages which interact with ezauth routes via forms. These pages can be overridden for aesthetics, but adding functional auth to a net/http web app should take minutes, not hours or days.

The goal is not to create a comprehensive and advanced auth library, but to make it trivial to incorporate the common use case of "adding login to my Go web app".

Reluctantly, I made the decision to implement auth fitting this description. By creating a public package, I can import future fixes into my disjoint projects, open the global community to make security suggestions, and help someone in the future get started more quickly.

ezauth's People

Contributors

mannders00 avatar

Stargazers

Siphiwe avatar Ayan Sheikh avatar Eugene Klimov avatar  avatar David A avatar Awad Diar avatar Rod Watkins avatar

Watchers

 avatar

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.