封装sso登入登出地址
This commit is contained in:
parent
58afabebe9
commit
9710c9ddd7
@ -1,8 +1,11 @@
|
|||||||
package sso
|
package sso
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk"
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -27,6 +30,7 @@ var HOST = requests.Host{
|
|||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
sdk.Client
|
sdk.Client
|
||||||
|
ident string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CodeAuth(req *CodeAuthRequest) (response *CodeAuthResponse, err error) {
|
func (c *Client) CodeAuth(req *CodeAuthRequest) (response *CodeAuthResponse, err error) {
|
||||||
@ -53,8 +57,38 @@ func (c *Client) SearchUser(req *SearchUserRequest) (response *SearchUserRespons
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetLoginUrl(redirectUrl string, env ...string) string {
|
||||||
|
uri := fmt.Sprintf("/admin/main/login?ident=%s&redirectUrl=%s", c.ident, url.QueryEscape(redirectUrl))
|
||||||
|
scheme, host := c.getSchemeAndHost(env...)
|
||||||
|
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) GetLogout(env ...string) string {
|
||||||
|
uri := fmt.Sprintf("/admin/main/logout?ident=%s&redirectUrl=", c.ident)
|
||||||
|
scheme, host := c.getSchemeAndHost(env...)
|
||||||
|
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Client) getSchemeAndHost(env ...string) (scheme, host string) {
|
||||||
|
rEnv := requests.RELEASE
|
||||||
|
if len(env) >= 1 {
|
||||||
|
rEnv = env[0]
|
||||||
|
}
|
||||||
|
host = HOST.Func(rEnv)
|
||||||
|
|
||||||
|
if rEnv == requests.RELEASE {
|
||||||
|
scheme = requests.HTTPS
|
||||||
|
} else {
|
||||||
|
scheme = requests.HTTP
|
||||||
|
}
|
||||||
|
scheme = strings.ToLower(scheme)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
|
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
|
||||||
client = &Client{}
|
client = &Client{}
|
||||||
|
client.ident = source
|
||||||
|
|
||||||
err = client.InitWithAccessKey(accesskey, secrect, source)
|
err = client.InitWithAccessKey(accesskey, secrect, source)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
11
services/sso/client_test.go
Normal file
11
services/sso/client_test.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package sso
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLoginUrl(t *testing.T) {
|
||||||
|
c, _ := NewClientWithAccessKey("stat.gaore.com.hk", "", "stat_gaore_com_hk")
|
||||||
|
t.Log(c.GetLoginUrl("http://stat.gaore.com.hk/web/user/login", requests.TEST))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user