Smart Hello: add more debug output (#14162)
This commit is contained in:
parent
454ea65f58
commit
20e0fba139
2 changed files with 14 additions and 9 deletions
|
|
@ -24,10 +24,9 @@ func InterceptRedirect(param string, stop bool) (func(req *http.Request, via []*
|
|||
return nil
|
||||
},
|
||||
func() (string, error) {
|
||||
var err error
|
||||
if val == "" {
|
||||
err = fmt.Errorf("%s not found", param)
|
||||
return "", fmt.Errorf("%s not found", param)
|
||||
}
|
||||
return val, err
|
||||
return val, nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,12 +73,18 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
})
|
||||
|
||||
resp, err := v.Do(req)
|
||||
if err == nil && resp.StatusCode != 200 {
|
||||
err = fmt.Errorf("status: %d", resp.StatusCode)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("authorize: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
u := resp.Request.URL
|
||||
context := resp.Request.URL.Query().Get("context")
|
||||
if context == "" {
|
||||
return nil, fmt.Errorf("missing context: %s", resp.Request.URL.String())
|
||||
}
|
||||
|
||||
data := url.Values{
|
||||
"loginID": {v.user},
|
||||
|
|
@ -120,7 +126,7 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
}
|
||||
|
||||
if err := v.DoJSON(req, &login); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("accounts.login: %w", err)
|
||||
}
|
||||
if login.ErrorCode != 0 {
|
||||
return nil, fmt.Errorf("%s: %s", login.ErrorMessage, login.ErrorDetails)
|
||||
|
|
@ -130,7 +136,7 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
var param request.InterceptResult
|
||||
v.Client.CheckRedirect, param = request.InterceptRedirect("access_token", true)
|
||||
|
||||
uri = fmt.Sprintf("https://auth.smart.com/oidc/op/v1.0/%s/authorize/continue?context=%s&login_token=%s", ApiKey, u.Query().Get("context"), login.SessionInfo.LoginToken)
|
||||
uri = fmt.Sprintf("https://auth.smart.com/oidc/op/v1.0/%s/authorize/continue?context=%s&login_token=%s", ApiKey, context, login.SessionInfo.LoginToken)
|
||||
req, _ = request.New(http.MethodGet, uri, nil, map[string]string{
|
||||
"user-agent": userAgent,
|
||||
"x-requested-with": "com.smart.hellosmart",
|
||||
|
|
@ -140,7 +146,7 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
|
||||
resp, err = v.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("token exchange: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
|
@ -148,7 +154,7 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
u, err = url.Parse(resp.Header.Get("location"))
|
||||
u, err := url.Parse(resp.Header.Get("location"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue