automatically login when anonymous user detected

This commit is contained in:
Cory Bennett
2017-08-27 13:55:48 -07:00
parent 1f345cedee
commit 21add544dc
3 changed files with 28 additions and 12 deletions
+11
View File
@@ -2,6 +2,7 @@ package main
import (
"fmt"
"net/http"
"os"
"path/filepath"
"runtime/debug"
@@ -70,6 +71,16 @@ func main() {
fig.ConfigDir = ".jira.d"
o := oreo.New().WithCookieFile(filepath.Join(jiracli.Homedir(), fig.ConfigDir, "cookies.js"))
o = o.WithPostCallback(
func(req *http.Request, resp *http.Response) (*http.Response, error) {
if resp.Header.Get("X-Ausername") == "anonymous" {
// we are not logged in, so force login now by running the "login" command
app.Parse([]string{"login"})
return o.Do(req)
}
return resp, nil
},
)
registry := []jiracli.CommandRegistry{
jiracli.CommandRegistry{