This package simplify the interaction with OAuth.io or oauthd using Golang.
Special thanks to Yamil Asusta from Sendgrid who is the original creator of this SDK.
go get github.com/oauth-io/sdk-go
This library was built to be unobtrusive. Meaning that handling codes is up to the user. Examples will be provided on how to use the library on common frameworks.
package main
import (
"fmt"
"github.com/oauth-io/sdk-go"
"github.com/go-martini/martini"
)
func main() {
m := martini.Classic()
oauth := oauthio.New("PUBLIC_KEY", "SECRET_KEY")
//redirect the user to the Facebook authorization page then redirect him to /oauth/redirect
m.Get("/signin", oauth.Redirect("facebook", "http://localhost:3000/oauth/redirect"))
//Once redirected, handle the callback and get back a oauthio.OAuthRequestObject object
m.Get("/oauth/redirect", oauth.Callback(func(res *oauthio.OAuthRequestObject, err error, rw http.ResponseWriter, req *http.Request) {
if err != nil {
fmt.Println(err)
return
}
r, _ := res.Me([]string{})
//fmt.Println(res.AccessToken, err)
fmt.Println(string(r))
}))
m.Run()
}
package main
import (
"fmt"
"github.com/oauth-io/sdk-go"
"github.com/gorilla/mux"
"net/http"
)
func main() {
m := mux.NewRouter()
oauth := oauthio.New("PUBLIC_KEY", "SECRET_KEY")
m.HandleFunc("/signin", oauth.Redirect("facebook", "http://localhost:3000/oauth/redirect"))
m.HandleFunc("/oauth/redirect", oauth.Callback(func(res *oauthio.OAuthRequestObject, err error, rw http.ResponseWriter, req *http.Request) {
if err != nil {
fmt.Println(err)
return
}
r, _ := res.Me([]string{})
//fmt.Println(res.AccessToken, err)
fmt.Println(string(r))
}))
http.Handle("/", m)
}
It is completely up to the user to decide where and how to store the tokens.
Enjoy, feel free to submit pull requests!