package example import ( "encoding/json" "errors" "fmt" "net/http" "github.com/RangelReale/osin" ) func HandleLoginPage(ar *osin.AuthorizeRequest, w http.ResponseWriter, r *http.Request) bool { r.ParseForm() if r.Method == "POST" && r.Form.Get("login") == "test" && r.Form.Get("password") == "test" { return true } w.Write([]byte("")) w.Write([]byte(fmt.Sprintf("LOGIN %s (use test/test)
", ar.Client.GetId()))) w.Write([]byte(fmt.Sprintf("
", r.URL.RawQuery))) w.Write([]byte("Login:
")) w.Write([]byte("Password:
")) w.Write([]byte("")) w.Write([]byte("
")) w.Write([]byte("")) return false } func DownloadAccessToken(url string, auth *osin.BasicAuth, output map[string]interface{}) error { // download access token preq, err := http.NewRequest("POST", url, nil) if err != nil { return err } if auth != nil { preq.SetBasicAuth(auth.Username, auth.Password) } pclient := &http.Client{} presp, err := pclient.Do(preq) if err != nil { return err } if presp.StatusCode != 200 { return errors.New("Invalid status code") } jdec := json.NewDecoder(presp.Body) err = jdec.Decode(&output) return err }