HMS-Core / hms-push-serverdemo-go

Golang sample code encapsulates APIs of the HUAWEI Push Kit server. It provides many sample programs for your reference or usage.
https://developer.huawei.com/consumer/cn/doc/development/HMS-Guides/push-introduction
Apache License 2.0
57 stars 39 forks source link

Refresh token is not work #3

Open chanchaitdg opened 3 years ago

chanchaitdg commented 3 years ago

Access token after refresh token is not replace on http request for send push notification. HTTP request still use previous access token.

Mike-mei commented 3 years ago

Which method do you use to refresh token? Please check whether this error is reported when you refresh token.

chanchaitdg commented 3 years ago

on executeApiOperation method: src/push/core/pushclient.go

when access token expried. isNeedRetry method get new access token but Authorization access token in request.Header is not change.

Maybe change on sendHttpRequest method: src/push/core/pushclient.go for fix it.


func (c *HttpPushClient) sendHttpRequest(ctx context.Context, request *httpclient.PushRequest, responsePointer interface{}) error {
    request.Header = []httpclient.HTTPOption{
        httpclient.SetHeader("Content-Type", "application/json;charset=utf-8"),
        httpclient.SetHeader("Authorization", "Bearer "+c.token),
    }

    resp, err := c.client.DoHttpRequest(ctx, request)
    if err != nil {
        return err
    }

    if err = json.Unmarshal(resp.Body, responsePointer); err != nil {
        return err
    }
    return nil
}
Mike-mei commented 3 years ago

This issue has been solved in the latest commit, please refer to afaab2fe7dd4cfcaa82a043cd65bbc5677117f6c