package main // Use golang.org/x/oauth2 client to test // Open url in browser: // http://localhost:14000/app import ( "fmt" "net/http" "github.com/RangelReale/osin" "github.com/RangelReale/osin/example" "golang.org/x/oauth2" ) func main() { config := osin.NewServerConfig() // goauth2 checks errors using status codes config.ErrorStatusCode = 401 server := osin.NewServer(config, example.NewTestStorage()) client := &oauth2.Config{ ClientID: "1234", ClientSecret: "aabbccdd", Endpoint: oauth2.Endpoint{ AuthURL: "http://localhost:14000/authorize", TokenURL: "http://localhost:14000/token", }, RedirectURL: "http://localhost:14000/appauth/code", } // Authorization code endpoint http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) { resp := server.NewResponse() defer resp.Close() if ar := server.HandleAuthorizeRequest(resp, r); ar != nil { if !example.HandleLoginPage(ar, w, r) { return } ar.Authorized = true server.FinishAuthorizeRequest(resp, r, ar) } if resp.IsError && resp.InternalError != nil { fmt.Printf("ERROR: %s\n", resp.InternalError) } osin.OutputJSON(resp, w, r) }) // Access token endpoint http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) { resp := server.NewResponse() defer resp.Close() if ar := server.HandleAccessRequest(resp, r); ar != nil { ar.Authorized = true server.FinishAccessRequest(resp, r, ar) } if resp.IsError && resp.InternalError != nil { fmt.Printf("ERROR: %s\n", resp.InternalError) } osin.OutputJSON(resp, w, r) }) // Information endpoint http.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) { resp := server.NewResponse() defer resp.Close() if ir := server.HandleInfoRequest(resp, r); ir != nil { server.FinishInfoRequest(resp, r, ir) } osin.OutputJSON(resp, w, r) }) // Application home endpoint http.HandleFunc("/app", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("
")) //w.Write([]byte(fmt.Sprintf("Login