logto-io / go

☁️ Logto Golang SDKs.
MIT License
19 stars 13 forks source link

bug: invalid_client; client authentication failed #74

Closed v0rs4 closed 1 year ago

v0rs4 commented 1 year ago

Describe the bug

I've come across this issue

unexpected status code: 401, response body: {"error":"invalid_client","error_description":"client authentication failed"}

Expected behavior

N/A

How to reproduce?

Context

N/A

Possible Fix

Apparently there's something wrong on this line

So,

I replaced

response, requestErr := client.PostForm(options.TokenEndpoint, values)

with

req, _ := http.NewRequest(http.MethodPost, options.TokenEndpoint, strings.NewReader(values.Encode()))

req.Header.Add("Authorization", "Basic <<<BASE64_ENCODED(CLIENT_ID:CLIENT_SECRET)>>>")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

response, requestErr := client.Do(req)

and it works now

I don't have deep knowledge in go but it seems that logtoClient.httpClient looses basic auth header somehow


Screenshots

waltcow commented 1 year ago

meet the same issue here

xiaoyijun commented 1 year ago

Fixed https://github.com/logto-io/go/pull/75

xiaoyijun commented 1 year ago

The new version was released. @v0rs4 @waltcow https://github.com/logto-io/go/releases/tag/v1.0.3