logto icon indicating copy to clipboard operation
logto copied to clipboard

bug: Go Web: Integrate Logto , "Traditional web" Application , FetchTokenByAuthorizationCode responsed "invalid_client"

Open itellsx opened this issue 2 years ago • 6 comments

Describe the bug

Go Web: Integrate Logto , "Traditional web" Application , FetchTokenByAuthorizationCode responsed "invalid_client"

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

Expected behavior

"Traditional web" Application fail ,but use "Single Page App" is ok

How to reproduce?

Context

OS: CentOS Linux release 7.9.2009 (Core)

Environment: docker svhd/logto prerelease

Logto version: <= v1.0.0-beta.9 Node version: v16.17.0

Postgres version: 14.2

Command of starting Logto: docker

Screenshots

itellsx avatar Sep 11 '22 11:09 itellsx

@xiaoyijun would you like to take a look? thanks

gao-sun avatar Sep 11 '22 14:09 gao-sun

Hi, @dzp-java. Could you please provide a minimum reproduction repo for us? A related sample code is also welcomed.

xiaoyijun avatar Sep 12 '22 01:09 xiaoyijun

@xiaoyijun Just according to the official instructions: https://docs.logto.io/zh-cn/docs/recipes/integrate-logto/go-web

and "Single Page App" secret find by browser : https://<logto-host>/api/applications/<appid>

itellsx avatar Sep 12 '22 02:09 itellsx

Currently, the single-page application does not have an AppSecret. If you want to use the Go SDK in the single-page application, just remove the AppSecret from the LogtoConfig:

logtoConfig := &client.LogtoConfig{
  Endpoint:  "http://localhost:3001",
  AppId:     "someAppId",
  Resources: []string{"someResource"},
}

By the way, if you're using a SPA, a client SDK ( React / Vue / Vanilla JS) is more suitable than a traditional web application SDK.

xiaoyijun avatar Sep 12 '22 04:09 xiaoyijun

Actually, I use "Traditional web" Application at Go SDK ; but server response : status code: 401, response body: {"error":"invalid_client","error_description":"client authentication failed"}

My guess is that there is a problem in judging the application type on the server side, not on the client side

itellsx avatar Sep 12 '22 06:09 itellsx

This works well in our gin-sample; we need more information about your program. @dzp-java , would you like to provide a minimum reproduction repo for us?

xiaoyijun avatar Sep 13 '22 01:09 xiaoyijun

I have a same problem.

logto'log shows 401 when a user sign in:

  <-- GET /sign-in/consent
  --> GET /sign-in/consent 200 9ms 220b
  <-- GET /index.b4d7740b.css
  <-- GET /api/.well-known/sign-in-exp
  <-- GET /api/.well-known/phrases
  <-- GET /index.d26ae494.js
  --> GET /index.b4d7740b.css 200 63ms 5.09kb
  --> GET /index.d26ae494.js 200 48ms 204.48kb
  --> GET /api/.well-known/sign-in-exp 200 71ms 685b
  --> GET /api/.well-known/phrases 200 73ms 1.47kb
  <-- GET /favicon.ico
  --> GET /favicon.ico 200 2ms 220b
  <-- POST /api/interaction/consent
  --> POST /api/interaction/consent 200 13ms 74b
  <-- GET /oidc/auth/tQZOVnZlOLRG3UZAKbB6s
  --> GET /oidc/auth/tQZOVnZlOLRG3UZAKbB6s 303 16ms 503b
  <-- GET /oidc/.well-known/openid-configuration
  --> GET /oidc/.well-known/openid-configuration 200 4ms 552b
  <-- POST /oidc/token
  --> POST /oidc/token 401 9ms 77b

I run it well on my localhost, but failed on cloud environment.

Could you please help me out? @xiaoyijun

chrisliu1995 avatar May 18 '23 15:05 chrisliu1995

@dzp-java Have you solved the problem?

chrisliu1995 avatar May 18 '23 15:05 chrisliu1995

I've come across the same problem too

I run gin-example against Traditional Web application and it returns

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

v0rs4 avatar May 20 '23 21:05 v0rs4

I've come across the same problem too

I run gin-example against Traditional Web application and it returns

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

You can try to use this sdk: https://github.com/CloudNativeGame/logto-go

chrisliu1995 avatar May 22 '23 08:05 chrisliu1995

This is caused by obsolete Logto go module.

Check and update your go.mod manually, remove possibly:

github.com/logto-io/go/core // legacy obsolete module
github.com/logto-io/go/client // save as above

and replace them with:

github.com/logto-io/go v1.0.3

Then run go mod tidy, everything should be fine.

kidlj avatar Nov 26 '23 08:11 kidlj