Authy is a go library that acts as an oauth authentication middleware for net/http, it aims to provide drop-in support for most OAuth 1 (not implemented yet) and 2 providers. It is inspired from node.js libraries such as grant or everyauth.
The current OAuth implementation is kinda rough and basic but should do the trick.
The current list of providers is a verbatim adaptation of the one provided by grant.
500px
amazon
angellist
appnet
asana
assembla
basecamp
bitbucket
bitly
box
buffer
cheddar
coinbase
dailymile
dailymotion
deezer
deviantart
digitalocean
disqus
dropbox
edmodo
elance
eventbrite
evernote
everyplay
eyeem
facebook
feedly
fitbit
flattr
flickr
flowdock
foursquare
geeklist
getpocket
github
gitter
goodreads
google
harvest
heroku
imgur
instagram
jawbone
linkedin
live
mailchimp
meetup
mixcloud
odesk
openstreetmap
paypal
podio
rdio
redbooth
reddit
runkeeper
salesforce
shopify
skyrock
slack
slice
soundcloud
spotify
stackexchange
stocktwits
strava
stripe
traxo
trello
tripit
tumblr
twitch
twitter
uber
vimeo
vk
withings
wordpress
xing
yahoo
yammer
yandex
zendesk
With martini:
server.go
package main
import (
"encoding/json"
"github.com/go-martini/martini"
"github.com/gophergala/authy/martini"
"github.com/martini-contrib/render"
"github.com/martini-contrib/sessions"
"os"
)
type Config struct {
Secret string `json:"secret"`
Authy authy.Config `json:"authy"`
}
func readConfig() (Config, error) {
f, err := os.Open("config.json")
if err != nil {
return Config{}, err
}
decoder := json.NewDecoder(f)
var config Config
decoder.Decode(&config)
return config, nil
}
func main() {
// read app config (and authy config)
config, err := readConfig()
if err != nil {
panic(err)
}
// setup Martini
m := martini.Classic()
m.Use(sessions.Sessions("authy", sessions.NewCookieStore([]byte(config.Secret))))
// register our middleware
m.Use(authy.Authy(config.Authy))
m.Use(render.Renderer())
// see the LoginRequired middleware, automatically redirect to the login page if necessary
m.Get("/generic_callback", authy.LoginRequired(), func(token authy.Token, r render.Render) {
r.HTML(200, "callback", token)
})
m.Run()
}
templates/callback.tmpl
<html>
<body>
<h2>{{.Value}} <small>({{.Scope}})</small></h2>
</body>
</html>
config.json
{
"authy": {
"login_page": "/login",
"callback": "/generic_callback",
"providers": {
"github": {
"key": "my-app-key",
"secret": "my-app-secret",
"scope": ["repo", "user:email"]
}
}
}
}