undo that last change, but noice error returns from EndSession

This commit is contained in:
David Sharnoff 2022-10-27 18:55:20 -07:00
parent a689c468ff
commit 5584414f53
2 changed files with 11 additions and 9 deletions

View file

@ -2,6 +2,8 @@ package client
import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
"reflect"
@ -78,8 +80,6 @@ type EndSessionCaller interface {
HttpClient() *http.Client
}
// CallEndSessionEndpoint terminates a session. The server may respond with
// a redirect, or it may not. If not, the returned URL will be nil.
func CallEndSessionEndpoint(request interface{}, authFn interface{}, caller EndSessionCaller) (*url.URL, error) {
req, err := httphelper.FormRequest(caller.GetEndSessionEndpoint(), request, Encoder, authFn)
if err != nil {
@ -90,17 +90,21 @@ func CallEndSessionEndpoint(request interface{}, authFn interface{}, caller EndS
return http.ErrUseLastResponse
}
resp, err := client.Do(req)
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("EndSession failure, %d status code: %s", resp.StatusCode, string(body))
}
location, err := resp.Location()
if err != nil {
if errors.Is(err, http.ErrNoLocation) {
return nil, nil
}
return nil, err
}
defer resp.Body.Close()
location, err := resp.Location()
if err != nil {
return nil, err
}
return location, nil
}

View file

@ -575,8 +575,6 @@ func RefreshAccessToken(rp RelyingParty, refreshToken, clientAssertion, clientAs
return client.CallTokenEndpoint(request, tokenEndpointCaller{RelyingParty: rp})
}
// EndSession terminates a session. The server may respond with
// a redirect, or it may not. If not, the returned URL will be nil.
func EndSession(rp RelyingParty, idToken, optionalRedirectURI, optionalState string) (*url.URL, error) {
request := oidc.EndSessionRequest{
IdTokenHint: idToken,