修改获取SSO登入登出URL方法
This commit is contained in:
parent
710f74a50c
commit
9a2e21d646
@ -1,11 +1,8 @@
|
|||||||
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 (
|
||||||
@ -17,8 +14,8 @@ var HOST = requests.Host{
|
|||||||
Func: func(s string, area string) string {
|
Func: func(s string, area string) string {
|
||||||
host := map[string]string{
|
host := map[string]string{
|
||||||
requests.RELEASE: "sso.gaore.com.hk",
|
requests.RELEASE: "sso.gaore.com.hk",
|
||||||
requests.PRE: "sso.gaore.com",
|
requests.PRE: "sso.gaore.com.hk",
|
||||||
requests.TEST: "sso.gaore.com",
|
requests.TEST: "sso.gaore.com.hk",
|
||||||
}
|
}
|
||||||
if s, ok := host[s]; ok {
|
if s, ok := host[s]; ok {
|
||||||
return s
|
return s
|
||||||
@ -57,34 +54,6 @@ 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
|
client.ident = source
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package sso
|
package sso
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoginUrl(t *testing.T) {
|
func TestLoginUrl(t *testing.T) {
|
||||||
c, _ := NewClientWithAccessKey("stat.gaore.com.hk", "", "stat_gaore_com_hk")
|
t.Log(GetLoginUrl("stat.gaore.com.hk", "http://stat.gaore.com.hk/web/user/login"))
|
||||||
t.Log(c.GetLoginUrl("http://stat.gaore.com.hk/web/user/login", requests.TEST))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_CodeAuth(t *testing.T) {
|
func TestClient_CodeAuth(t *testing.T) {
|
||||||
|
27
services/sso/url.go
Normal file
27
services/sso/url.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package sso
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"golib.gaore.com/GaoreGo/haiwai-common-sdk-go/sdk/requests"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetLoginUrl(ident string, redirectUrl string, env ...string) string {
|
||||||
|
uri := fmt.Sprintf("/admin/main/login?ident=%s&redirectUrl=%s", ident, url.QueryEscape(redirectUrl))
|
||||||
|
scheme, host := getSchemeAndHost(env...)
|
||||||
|
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetLogout(ident string, env ...string) string {
|
||||||
|
uri := fmt.Sprintf("/admin/main/logout?ident=%s&redirectUrl=", ident)
|
||||||
|
scheme, host := getSchemeAndHost(env...)
|
||||||
|
return fmt.Sprintf("%s://%s%s", scheme, host, uri)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSchemeAndHost(env ...string) (scheme, host string) {
|
||||||
|
env = append(env, requests.RELEASE)
|
||||||
|
host = HOST.Func(env[0], "")
|
||||||
|
scheme = strings.ToLower(requests.HTTPS)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user