Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO client does not return headers from http response #60

Open
arihant30 opened this issue Feb 4, 2022 · 1 comment
Open

GO client does not return headers from http response #60

arihant30 opened this issue Feb 4, 2022 · 1 comment

Comments

@arihant30
Copy link

arihant30 commented Feb 4, 2022

The Login API is supposed to sign-in a User and return a "Set-Cookie" header that contains the refresh token and access token, but the client does not read the headers from the response, nor does it return them.
A workaround is to call the login API yourself instead of using the go-client and reading the headers from the response.

func (rc *restClient) Do() error {
	req, err := http.NewRequest("POST", rc.Uri.String(), rc.Body)
	if err != nil {
		return err
	}
	for key, val := range rc.Headers {
		req.Header.Set(key, val)
	}
	resp, err := rc.HTTPClient.Do(req)
	if err != nil {
		return err
	}
// Reading the headers from the response
	key := resp.Header.Values("Set-Cookie")
	if key != nil {
		rc.Cookie = key
	}
	defer resp.Body.Close()
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		return errors.BaseBadRequest
	} else {
		rc.ErrorRef = nil
		if _, ok := rc.ResponseRef.(*BaseHTTPResponse); !ok {
			err = json.NewDecoder(resp.Body).Decode(rc.ResponseRef)
		}
	}
	return err
}

This is a workaround that I have used.

@mooreds
Copy link
Contributor

mooreds commented Feb 6, 2022

Thanks for the feedback @arihant30 !

The client libraries cover ~95% of the functionality of the REST API, but not 100%. Cookies, JWT authentication, and http status codes are some of the holes.

I'm leaving this open for possible future work (which would take place in https://github.com/fusionauth/fusionauth-client-builder so that every client library could benefit), but since there's a straightforward workaround, can't commit to a timeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants