Skip to content

Commit

Permalink
Merge pull request #10 from binjianwu/logout-param
Browse files Browse the repository at this point in the history
Add logout param support
  • Loading branch information
geoffgarside committed May 23, 2017
2 parents 74a3eae + 06985ad commit 2722b1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
.idea

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
32 changes: 23 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,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
Expand All @@ -25,8 +26,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.
Expand All @@ -50,10 +52,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,
}
}

Expand Down Expand Up @@ -115,6 +118,17 @@ func (c *Client) LogoutUrlForRequest(r *http.Request) (string, error) {
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()
}

return u.String(), nil
}

Expand Down

0 comments on commit 2722b1d

Please sign in to comment.