X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/feb290061b91fa059aefd251ed3c3532b32620ea..23d90de7344ae39d1d0082a369b0dc5e9086531d:/sdk/go/arvados/login.go diff --git a/sdk/go/arvados/login.go b/sdk/go/arvados/login.go index 75ebc81c14..26c04b2c13 100644 --- a/sdk/go/arvados/login.go +++ b/sdk/go/arvados/login.go @@ -6,12 +6,15 @@ package arvados import ( "bytes" + "encoding/json" "net/http" ) type LoginResponse struct { - RedirectLocation string - HTML bytes.Buffer + RedirectLocation string `json:"redirect_location,omitempty"` + Token string `json:"token,omitempty"` + Message string `json:"message,omitempty"` + HTML bytes.Buffer `json:"-"` } func (resp LoginResponse) ServeHTTP(w http.ResponseWriter, req *http.Request) { @@ -19,6 +22,12 @@ func (resp LoginResponse) ServeHTTP(w http.ResponseWriter, req *http.Request) { if resp.RedirectLocation != "" { w.Header().Set("Location", resp.RedirectLocation) w.WriteHeader(http.StatusFound) + } else if resp.Token != "" || resp.Message != "" { + w.Header().Set("Content-Type", "application/json") + if resp.Token == "" { + w.WriteHeader(http.StatusUnauthorized) + } + json.NewEncoder(w).Encode(resp) } else { w.Header().Set("Content-Type", "text/html") w.Write(resp.HTML.Bytes())