Skip to content

🐛 Bug Report - client authentication must only be provided using one mechanism #52

@twsl

Description

@twsl

Bug description

I'm trying to implement my own oauth implementation.
Trying this with logto returns '(invalid_request) client authentication must only be provided using one mechanism'

oauth2_query_params = dict(
redirect_url=redirect_uri,
client_secret=self.client_secret,
authorization_response=authorization_response,
)
oauth2_query_params.update(request.query_params)
token_url, headers, content = self._oauth_client.prepare_token_request(
self._token_endpoint,
**oauth2_query_params,
)
headers.update({"Accept": "application/json"})
auth = httpx.BasicAuth(self.client_id, self.client_secret)

Here the client_secret is set both for the Authorization header and to the request body.

According to this post and other posts only one is supposed to be there. header seems to be preferred based on my limited knowledge.

Simply removing line 113 client_secret=self.client_secret, solves my problem

Reproduction URL

No response

Reproduction steps

  1. Add middleware
class MyOAuth2(BaseOAuth2):
    name = "my"
    AUTHORIZATION_URL = os.getenv("AUTHORIZE_URL")
    ACCESS_TOKEN_URL = os.getenv("TOKEN_URL")
    REFRESH_TOKEN_URL = os.getenv("REFRESH_TOKEN_URL") or ""

app.add_middleware(
        OAuth2Middleware,
        config=OAuth2Config(
            allow_http=True,
            clients=[
                OAuth2Client(
                    backend=MyOAuth2,
                    client_id=os.getenv("CLIENT_ID") or "",
                    client_secret=os.getenv("CLIENT_SECRET") or "",
                    # redirect_uri=os.getenv("REDIRECT_URI"),
                    scope=scopes.split(" "),
                )
            ],
        ),
        callback=on_auth_success,
        on_error=on_auth_error,
    )
  1. Navigate to /oauth2/my/authorize

Screenshots

No response

Logs

No response

Browsers

Firefox, Chrome

OS

Windows, Linux

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions