I created an OAuth2 server library in Go, that aims to be a complete
implementation of the RFC.
https://github.com/RangelReale/osin
It already implements most of the core spec, but has not been in production
yet, so it should be considered beta quality.
As I am new to Go (who isn't?), I am still not sure about library design
patterns, like configurations and callbacks. Any comments on the library
interface are highly welcomed.
This is a sample of the implementation, there are 3 working examples on the
examples directory.
import "github.com/RangelReale/osin"
// TestStorage implements the "osin.Storage" interface
server := osin.NewServer(osin.NewServerConfig(), &TestStorage{})
output := osin.NewResponseOutputJSON()
// Authorization code endpoint
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
resp := osin.NewResponse()
if ar := server.HandleAuthorizeRequest(resp, r); ar != nil {
// HANDLE LOGIN PAGE HERE
ar.Authorized = true
server.FinishAuthorizeRequest(resp, r, ar)
}
output.Output(resp, w, r)
})
// Access token endpoint
http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
resp := osin.NewResponse()
if ar := server.HandleAccessRequest(resp, r); ar != nil {
ar.Authorized = true
server.FinishAccessRequest(resp, r, ar)
}
output.Output(resp, w, r)
})
http.ListenAndServe(":14000", nil)
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.