What the message looks like
{"error":"invalid_client","error_description":"Client authentication failed"}
HTTP/1.1 401 UnauthorizedCommon causes
- The client secret is wrong, was rotated, has expired, or was copied with a space or line break.
- The client uses another authentication method than the IdP expects, for example
client_secret_postagainstclient_secret_basic. - The client ID is mistyped, belongs to another realm or tenant, or the client was deleted or disabled.
- The client is set as a public client without a secret, but the app sends one, or it is confidential and sends none.
- A proxy or a form filler changes the
Authorizationheader.
Check
- Which auth methods does the IdP accept?
curl -s https://idp.example.com/.well-known/openid-configuration | jq '.token_endpoint, .token_endpoint_auth_methods_supported' - Which client ID is configured in Nextcloud?
- Find the error in the app log
grep -i invalid_client /var/www/nextcloud/data/nextcloud.log | tail -n 5 - Hidden characters in the stored secret value?
printf '%s' "$CLIENT_SECRET" | od -c | tail -n 3
Fix
- Open the client in the IdP, generate or copy the secret again, and paste it without spaces or line breaks into the app.
- Check the expiry date of the secret. Some providers, for example Microsoft Entra ID, let secrets expire, so create a new one and update the app before the old one stops.
- Match the authentication method: set the client in the IdP and the app to the same one,
client_secret_basicorclient_secret_post. - Check that the client is enabled, is of type confidential when it uses a secret, and belongs to the realm or tenant of the issuer URL you use.
- Try the login again and read the IdP's own log for the exact reason.
Typical scenario
In Microsoft Entra ID an app registration secret was renewed. In the Nextcloud provider, the secret ID now sits there by mistake instead of the secret value, which is shown only once. The token call after login returns invalid_client, and the error appears in the Nextcloud log right after the redirect. First check that the provider configuration really holds the secret's value, without a space or line break at the end.
FAQ
What is the difference to invalid_grant?
invalid_client means the app could not prove its identity. invalid_grant means the code or token was bad: used twice, expired, or issued to another redirect address.
Is a wrong user password the cause?
No. The user is already signed in at this point. The failure is between your app and the IdP, so changing the user's password will not help.
Why does the error suddenly appear without any change on my side?
With some providers client secrets expire, in Microsoft Entra for example with a lifetime chosen at creation. Once it expires, the token call fails with invalid_client from that day on, although you touched nothing. Note the expiry date and renew in time.
What are client_secret_basic and client_secret_post?
They are two ways to send the secret to the token endpoint, in an HTTP Basic header or in the form body. If the IdP expects one and the app sends the other, you get invalid_client. The method is listed in the metadata under the supported authentication methods.
Does the client type at the IdP matter?
Yes. If the client is created there as confidential, the app must send a secret. If it is public, the IdP expects none, and one sent along can cause trouble. The client type at the IdP has to match the configuration in the app.