feat: return oidc.Error in case of call token failure (#571)

This commit is contained in:
Célian GARCIA 2024-04-01 15:55:22 +02:00 committed by GitHub
parent 910f55ea7b
commit c89d0ed970
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 19 deletions

View file

@ -2,7 +2,6 @@ package client
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
@ -251,25 +250,11 @@ func CallDeviceAccessTokenEndpoint(ctx context.Context, request *DeviceAccessTok
req.SetBasicAuth(request.ClientID, request.ClientSecret)
}
httpResp, err := caller.HttpClient().Do(req)
if err != nil {
resp := new(oidc.AccessTokenResponse)
if err := httphelper.HttpRequest(caller.HttpClient(), req, &resp); err != nil {
return nil, err
}
defer httpResp.Body.Close()
resp := new(struct {
*oidc.AccessTokenResponse
*oidc.Error
})
if err = json.NewDecoder(httpResp.Body).Decode(resp); err != nil {
return nil, err
}
if httpResp.StatusCode == http.StatusOK {
return resp.AccessTokenResponse, nil
}
return nil, resp.Error
return resp, nil
}
func PollDeviceAccessTokenEndpoint(ctx context.Context, interval time.Duration, request *DeviceAccessTokenRequest, caller TokenEndpointCaller) (*oidc.AccessTokenResponse, error) {