Skip to content

Commit 834c4e9

Browse files
committed
fix: fix loginURL/logoutURL generate error
1 parent d1fdc6b commit 834c4e9

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

cas.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,37 @@ package juanjiCAS
33
import "net/url"
44

55
type CAS struct {
6-
domain *url.URL
7-
sendKey string
6+
frontend *url.URL
7+
backend *url.URL
8+
sendKey string
89
}
910

1011
func New(domain ...string) *CAS {
1112
c := &CAS{}
1213
if len(domain) == 0 {
13-
return c.SetDomain("https://api.cas.juanji.tech")
14+
return c.SetDomain("https://api.cas.juanji.tech").
15+
SetFrontendDomain("https://cas.juanji.tech")
1416
}
1517
return c.SetDomain(domain[0])
1618
}
1719

20+
// SetDomain set backend domain
1821
func (c *CAS) SetDomain(domain string) *CAS {
1922
u, err := url.Parse(domain)
2023
if err != nil {
2124
panic(err)
2225
}
23-
c.domain = u
26+
c.backend = u
27+
return c
28+
}
29+
30+
// SetFrontendDomain set frontend domain
31+
func (c *CAS) SetFrontendDomain(domain string) *CAS {
32+
u, err := url.Parse(domain)
33+
if err != nil {
34+
panic(err)
35+
}
36+
c.frontend = u
2437
return c
2538
}
2639

notify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (c *CAS) Notify(notice *Notice) error {
1717
return ErrNotSetSendKey
1818
}
1919
resp := Resp{}
20-
err := gout.POST(c.domain.JoinPath("/api/notify/send/" + c.sendKey).String()).
20+
err := gout.POST(c.backend.JoinPath("/api/notify/send/" + c.sendKey).String()).
2121
SetJSON(notice).
2222
BindJSON(&resp).Do()
2323
if err != nil {

serviceValidate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import (
55
)
66

77
func (c *CAS) GetLoginURL(redirectURL string) string {
8-
u := c.domain.JoinPath("/login")
8+
u := c.frontend.JoinPath("/login")
99
q := u.Query()
1010
q.Set("service", redirectURL)
1111
u.RawQuery = q.Encode()
1212
return u.String()
1313
}
1414

1515
func (c *CAS) GetLogoutURL(redirectURL string) string {
16-
u := c.domain.JoinPath("/logout")
16+
u := c.frontend.JoinPath("/logout")
1717
q := u.Query()
1818
q.Set("service", redirectURL)
1919
u.RawQuery = q.Encode()
2020
return u.String()
2121
}
2222

2323
func (c *CAS) GetValidateURL(ticket string, redirectURL string) string {
24-
u := c.domain.JoinPath("/serviceValidate")
24+
u := c.backend.JoinPath("/serviceValidate")
2525
q := u.Query()
2626
q.Set("ticket", ticket)
2727
q.Set("service", redirectURL)
@@ -33,7 +33,7 @@ func (c *CAS) GetValidateURL(ticket string, redirectURL string) string {
3333
// NOT SUPPORT YET
3434
// deprecated
3535
func (c *CAS) getProxyValidateURL(ticket string, redirectURL string) string {
36-
u := c.domain.JoinPath("/proxyValidate")
36+
u := c.backend.JoinPath("/proxyValidate")
3737
q := u.Query()
3838
q.Set("ticket", ticket)
3939
q.Set("service", redirectURL)

0 commit comments

Comments
 (0)