This is actually not really an app, but a library.

I was inspired by some of the auth middlewares available for popular node.js frameworks such as grant or everyauth.

My entry is mainly based on grant in that it providers only oauth integration for golang. It takes care of implementation oddities and allows developers to insert the auth mechanism with very little code.

For example using Martini:

import (
    "github.com/go-martini/martini"
    "github.com/gophergala/authy/martini"
)

func main() {
    // read config from somewhere
    config, err := readConfig()
    if err != nil {
        panic(err)
    }

    m := martini.Classic()

    // authy needs a session to be available
    m.Use(sessions.Sessions("authy", sessions.NewCookieStore([]byte(config.Secret))))
    // setup authy
    m.Use(authy.Authy(config.Authy))
    m.Use(render.Renderer())

    // pass the LoginRequired middleware to redirect the user automatically to the login page
    m.Get("/generic_callback", authy.LoginRequired(), func(token authy.Token, r render.Render) {
        r.HTML(200, "callback", token)
    })

    m.Run()
}

The config just need contains the providers the user want to use, the key and secret and finally the scope they want for everything to work. It also provides some conveniences like redirecting the user to login pages when the token is missing.

Built With

  • github.com/google/go-querystring/query
  • golang
  • martini
Share this project:
×

Updates