Skip to content

Commit 2722b1d

Browse files
authored
Merge pull request #10 from binjianwu/logout-param
Add logout param support
2 parents 74a3eae + 06985ad commit 2722b1d

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Folders
77
_obj
88
_test
9+
.idea
910

1011
# Architecture specific extensions/prefixes
1112
*.[568vq]

client.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import (
1414

1515
// Client configuration options
1616
type Options struct {
17-
URL *url.URL // URL to the CAS service
18-
Store TicketStore // Custom TicketStore, if nil a MemoryStore will be used
19-
Client *http.Client // Custom http client to allow options for http connections
17+
URL *url.URL // URL to the CAS service
18+
Store TicketStore // Custom TicketStore, if nil a MemoryStore will be used
19+
Client *http.Client // Custom http client to allow options for http connections
20+
SendService bool // Custom sendService to determine whether you need to send service param
2021
}
2122

2223
// Client implements the main protocol
@@ -25,8 +26,9 @@ type Client struct {
2526
tickets TicketStore
2627
client *http.Client
2728

28-
mu sync.Mutex
29-
sessions map[string]string
29+
mu sync.Mutex
30+
sessions map[string]string
31+
sendService bool
3032
}
3133

3234
// NewClient creates a Client with the provided Options.
@@ -50,10 +52,11 @@ func NewClient(options *Options) *Client {
5052
}
5153

5254
return &Client{
53-
url: options.URL,
54-
tickets: tickets,
55-
client: client,
56-
sessions: make(map[string]string),
55+
url: options.URL,
56+
tickets: tickets,
57+
client: client,
58+
sessions: make(map[string]string),
59+
sendService: options.SendService,
5760
}
5861
}
5962

@@ -115,6 +118,17 @@ func (c *Client) LogoutUrlForRequest(r *http.Request) (string, error) {
115118
return "", err
116119
}
117120

121+
if c.sendService {
122+
service, err := requestURL(r)
123+
if err != nil {
124+
return "", err
125+
}
126+
127+
q := u.Query()
128+
q.Add("service", sanitisedURLString(service))
129+
u.RawQuery = q.Encode()
130+
}
131+
118132
return u.String(), nil
119133
}
120134

0 commit comments

Comments
 (0)