Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
luojielin committed Dec 14, 2021
1 parent 9c396b0 commit adca890
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/authentication/authentication_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (c *Client) SendHttpRequestManage(url string, method string, query string,
req.Header.Add("x-authing-userpool-id", ""+c.UserPoolId)
req.Header.Add("x-authing-request-from", constant.SdkType)
req.Header.Add("x-authing-sdk-version", constant.SdkVersion)
req.Header.Add("x-authing-app-id", ""+constant.AppId)
req.Header.Add("x-authing-app-id", ""+c.AppId)

res, err := c.HttpClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -510,11 +510,10 @@ func (c *Client) SendHttpRestRequest(url string, method string, token *string, v
token = &selfToken
}
req.Header.Add("Authorization", "Bearer "+*token)

req.Header.Add("x-authing-userpool-id", ""+c.UserPoolId)
req.Header.Add("x-authing-request-from", constant.SdkType)
req.Header.Add("x-authing-sdk-version", constant.SdkVersion)
req.Header.Add("x-authing-app-id", ""+constant.AppId)
req.Header.Add("x-authing-app-id", ""+c.AppId)
res, err := c.HttpClient.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -551,7 +550,7 @@ func (c *Client) SendHttpRestRequestNotToken(url string, method string, variable
req.Header.Add("x-authing-userpool-id", ""+c.UserPoolId)
req.Header.Add("x-authing-request-from", constant.SdkType)
req.Header.Add("x-authing-sdk-version", constant.SdkVersion)
req.Header.Add("x-authing-app-id", ""+constant.AppId)
req.Header.Add("x-authing-app-id", ""+c.AppId)
res, err := c.HttpClient.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1049,7 +1048,7 @@ func (c *Client) SendHttpRequestCustomTokenManage(url string, method string, tok
req.Header.Add("x-authing-userpool-id", ""+c.UserPoolId)
req.Header.Add("x-authing-request-from", constant.SdkType)
req.Header.Add("x-authing-sdk-version", constant.SdkVersion)
req.Header.Add("x-authing-app-id", ""+constant.AppId)
req.Header.Add("x-authing-app-id", ""+c.AppId)

res, err := c.HttpClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -1222,7 +1221,11 @@ func (c *Client) Logout() (*model.CommonMessageAndCode, error) {

func (c *Client) LogoutByToken(token string) (*model.CommonMessageAndCode, error) {
url := fmt.Sprintf("%s/api/v2/logout?app_id=%s", c.Host, c.AppId)
b, err := c.SendHttpRestRequest(url, http.MethodGet, &token, nil)
variables := make(map[string]interface{})

variables["withCredentials"] = true
fmt.Println(url)
b, err := c.SendHttpRestRequest(url, http.MethodGet, &token, variables)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions lib/authentication/authentication_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ const (
UserPool = ""
)

func TestClient_LogoutByToken(t *testing.T) {
authenticationClient := NewClient(AppId, Secret, "https://hfggf.authing.cn")
authenticationClient.UserPoolId = UserPool
model := model.LoginByEmailInput{}
model.Email = "[email protected]"
model.Password = "zy"
user, err := authenticationClient.LoginByEmail(model)
if err != nil {
fmt.Println(err)
}
fmt.Println(*user.Token)
res, err := authenticationClient.LogoutByToken(*(user.Token))
fmt.Println(res, err)
fmt.Println(authenticationClient.CheckLoginStatus(*(user.Token)))
}

func TestClient_BuildAuthorizeUrlByOidc(t *testing.T) {
authenticationClient := NewClient(AppId, Secret)
authenticationClient.Protocol = constant.OIDC
Expand Down

0 comments on commit adca890

Please sign in to comment.