package main // Open url in browser: // http://localhost:14000/app import ( "database/sql" "fmt" "github.com/RangelReale/osin" "github.com/RangelReale/osin/example" "github.com/felipeweb/osin-mysql" _ "github.com/go-sql-driver/mysql" "net/http" "net/url" ) func main() { urldb := "root:@tcp(localhost:3306)/osin?parseTime=true" db, err := sql.Open("mysql", urldb) if err != nil { panic(err) } store := mysql.New(db, "osin_") err = store.CreateSchemas() if err != nil { panic(err) } cfg := osin.NewServerConfig() cfg.AllowGetAccessRequest = true cfg.AllowClientSecretInParams = true server := osin.NewServer(cfg, store) // 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