From ead83a6dc56a8187c712efe8c5e85c505dfad6cb Mon Sep 17 00:00:00 2001 From: Jaywoods <1160181053@qq.com> Date: Fri, 10 Feb 2017 15:51:26 +0800 Subject: [PATCH 1/2] Add logout param support --- _examples/cas-dumper.go | 1 + client.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/_examples/cas-dumper.go b/_examples/cas-dumper.go index dd2af08..fbe051d 100644 --- a/_examples/cas-dumper.go +++ b/_examples/cas-dumper.go @@ -64,6 +64,7 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if r.URL.Path == "/logout" { + r.URL.Path = "" cas.RedirectToLogout(w, r) return } diff --git a/client.go b/client.go index 0f91cd4..99c9de2 100644 --- a/client.go +++ b/client.go @@ -114,6 +114,15 @@ func (c *Client) LogoutUrlForRequest(r *http.Request) (string, error) { return "", err } + service, err := requestURL(r) + if err != nil { + return "", err + } + + q := u.Query() + q.Add("service", sanitisedURLString(service)) + u.RawQuery = q.Encode() + return u.String(), nil } From 06985ad899c2f6162b10ae64c5c0cb4775b28569 Mon Sep 17 00:00:00 2001 From: Jaywoods <1160181053@qq.com> Date: Sat, 18 Feb 2017 10:49:32 +0800 Subject: [PATCH 2/2] [ADD]param of the judgment --- .gitignore | 1 + _examples/cas-dumper.go | 1 - client.go | 37 +++++++++++++++++++++---------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index daf913b..0c9e329 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Folders _obj _test +.idea # Architecture specific extensions/prefixes *.[568vq] diff --git a/_examples/cas-dumper.go b/_examples/cas-dumper.go index fbe051d..dd2af08 100644 --- a/_examples/cas-dumper.go +++ b/_examples/cas-dumper.go @@ -64,7 +64,6 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if r.URL.Path == "/logout" { - r.URL.Path = "" cas.RedirectToLogout(w, r) return } diff --git a/client.go b/client.go index 99c9de2..dfd87bb 100644 --- a/client.go +++ b/client.go @@ -13,9 +13,10 @@ import ( // Client configuration options type Options struct { - URL *url.URL // URL to the CAS service - Store TicketStore // Custom TicketStore, if nil a MemoryStore will be used - Client *http.Client // Custom http client to allow options for http connections + URL *url.URL // URL to the CAS service + Store TicketStore // Custom TicketStore, if nil a MemoryStore will be used + Client *http.Client // Custom http client to allow options for http connections + SendService bool // Custom sendService to determine whether you need to send service param } // Client implements the main protocol @@ -24,8 +25,9 @@ type Client struct { tickets TicketStore client *http.Client - mu sync.Mutex - sessions map[string]string + mu sync.Mutex + sessions map[string]string + sendService bool } // NewClient creates a Client with the provided Options. @@ -49,10 +51,11 @@ func NewClient(options *Options) *Client { } return &Client{ - url: options.URL, - tickets: tickets, - client: client, - sessions: make(map[string]string), + url: options.URL, + tickets: tickets, + client: client, + sessions: make(map[string]string), + sendService: options.SendService, } } @@ -114,14 +117,16 @@ func (c *Client) LogoutUrlForRequest(r *http.Request) (string, error) { return "", err } - service, err := requestURL(r) - if err != nil { - return "", err - } + if c.sendService { + service, err := requestURL(r) + if err != nil { + return "", err + } - q := u.Query() - q.Add("service", sanitisedURLString(service)) - u.RawQuery = q.Encode() + q := u.Query() + q.Add("service", sanitisedURLString(service)) + u.RawQuery = q.Encode() + } return u.String(), nil }