package sso import ( "fmt" "gitlink.org.cn/cloudream/common/consts/errorcode" "gitlink.org.cn/cloudream/common/utils/http2" "gitlink.org.cn/cloudream/common/utils/serder" "net/url" "strings" ) type SSOInfoResp struct { NickName string `json:"nickName"` Roles []string `json:"roles"` ID string `json:"id"` Username string `json:"username"` } func (c *Client) GetSSOInfo(token string) (*SSOInfoResp, error) { targetUrl, err := url.JoinPath(c.baseURL, "/admin/info") if err != nil { return nil, err } resp, err := http2.GetJSON(targetUrl, http2.RequestParam{ Header: map[string]string{ "Authorization": token, "Host": "ai4m.jointcloud.net", "Connection": "keep-alive", }, }) if err != nil { return nil, err } contType := resp.Header.Get("Content-Type") if strings.Contains(contType, http2.ContentTypeJSON) { var codeResp response[SSOInfoResp] if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { return nil, fmt.Errorf("parsing response: %w", err) } if codeResp.Code == errorcode.OK { return &codeResp.Data, nil } return nil, codeResp.ToError() } return nil, fmt.Errorf("unknow response content type: %s", contType) }