# LOGIN\_ERROR: ... clientId=null, userId=null....., error=invalid\_code

**URL:** <https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714>\
**Category:** Miscellanaeous\
**Created:** [March 16, 2020, 2:31pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714 "2020-03-16T14:31:30Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![formicheedintorni](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/formicheedintorni/32/148_2.png) [@formicheedintorni](https://forum.keycloak.org/u/formicheedintorni)\
**Post date:** [March 16, 2020, 2:31pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/1 "2020-03-16T14:31:30Z")

</div>

Hi,  
I knew that some people cannot log in keycloak. I found in the log file this error:

16927:2020-03-16 12:15:48,621 WARN [org.keycloak.events] (default task-760) type=LOGIN\_ERROR, realmId=test, clientId=null, userId=null, ipAddress=…, error=invalid\_code

I can’t find a solution by google and I don’t understand because of that.  
Does anyone have an idea?  
Thanks,

Michela

---

<div class="post-metadata">

**Author:** ![ddezoysa](https://avatars.discourse-cdn.com/v4/letter/d/b2d939/32.png) [@ddezoysa](https://forum.keycloak.org/u/ddezoysa)\
**Post date:** [April 6, 2020, 4:47pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/2 "2020-04-06T16:47:05Z")

</div>

Hi,

I’m getting the same issue with Keycloak 9.0.2.  
16:44:29,236 WARN [org.keycloak.events] (default task-5) type=LOGIN\_ERROR, realmId=master, clientId=null, userId=null, ipAddress=89.35.196.164, error=expired\_code, restart\_after\_timeout=true, authSessionParentId=bd1ed448-cd12-4884-b3a0-e8e446af09eb, authSessionTabId=7fky2Ttp-X8

Any reason?

Thanks  
Dinuth

---

<div class="post-metadata">

**Author:** ![Akanksha14](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@Akanksha14](https://forum.keycloak.org/u/Akanksha14)\
**Post date:** [April 6, 2020, 5:52pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/3 "2020-04-06T17:52:24Z")

</div>

Yours just looks like the login session was left as is for too long leading the access token to expire and prompting a restart of the session. Are you sure you’re getting this everytime you try to login?

I’m not sure about the original error posted.

---

<div class="post-metadata">

**Author:** ![Mariusz](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/mariusz/32/3101_2.png) [@Mariusz](https://forum.keycloak.org/u/Mariusz)\
**Post date:** [April 23, 2020, 10:19am UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/4 "2020-04-23T10:19:11Z")

</div>

I’m also experiencing this “userId=null” since last monday. Did any of you found an explanation?

I’m getting logs like:

type=LOGIN\_ERROR, realmId=XXX, clientId=XXX, userId=null, ipAddress=XXXXXXXXXXX, error=invalid\_user\_credentials, auth\_method=openid-connect, auth\_type=code, response\_type=code,

I also found some errors about FB OAuth authentication:

2020-04-23 11:37:56,101 ERROR [org.keycloak.broker.oidc.AbstractOAuth2IdentityProvider] (default task-8) Failed to make identity provider oauth callback: org.keycloak.broker.provider.IdentityBrokerException: No access token available in OAuth server response: {“error”:{“message”:“This authorization code has been used.”,“type”:“OAuthException”,“code”:100,“error\_subcode”:36009,“fbtrace\_id”:“AGiesgtv1lOhK1fakT8lis8”}}

Is that anway connected? We are running KC 9.0.0

---

<div class="post-metadata">

**Author:** ![haeussler247](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/haeussler247/32/1204_2.png) [@haeussler247](https://forum.keycloak.org/u/haeussler247)\
**Post date:** [May 3, 2020, 4:19pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/5 "2020-05-03T16:19:44Z")

</div>

@Mariusz

It looks like the login failed because of the wrong credentials. Is there a user with that credentials available in your realm?

The FB OAuth error looks like a used auth orization code. But I don’t have a lot of experience with the FB Login Method.

Best Regards,  
Johannes

---

<div class="post-metadata">

**Author:** ![Mariusz](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/mariusz/32/3101_2.png) [@Mariusz](https://forum.keycloak.org/u/Mariusz)\
**Post date:** [May 4, 2020, 6:31am UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/6 "2020-05-04T06:31:53Z")

</div>

Hi @haeussler247, we found out that those errors (and many more) were caused by broadcasting method, we used UDP instead of TCP, and our ACC environment was interfering with PROD servers. After change from UDP to TCP all is fine.

---

<div class="post-metadata">

**Author:** ![haeussler247](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/haeussler247/32/1204_2.png) [@haeussler247](https://forum.keycloak.org/u/haeussler247)\
**Post date:** [May 5, 2020, 10:35am UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/7 "2020-05-05T10:35:37Z")

</div>

Perfect,  
I’m happy to hear everything is fine now.

Best Regards  
Johannes

---

<div class="post-metadata">

**Author:** ![davidlara](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@davidlara](https://forum.keycloak.org/u/davidlara)\
**Post date:** [July 21, 2020, 7:43pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/8 "2020-07-21T19:43:22Z")

</div>

Hi All!  
I have the same issue, i already try change the UDP to TCP, and still not working…

 ![log](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/8/81c22e8b78c6f2eefd7b69452c583877a55ba0b6.png)  
any advices?  
thanks!

---

<div class="post-metadata">

**Author:** ![andrei](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@andrei](https://forum.keycloak.org/u/andrei)\
**Post date:** [August 8, 2020, 6:34pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/9 "2020-08-08T18:34:51Z")

</div>

In my case the clientId had a minus inside:

> my-client-id

Removing it solved the problem

---

<div class="post-metadata">

**Author:** ![burc](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@burc](https://forum.keycloak.org/u/burc)\
**Post date:** [February 27, 2021, 5:34pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/10 "2021-02-27T17:34:28Z")

</div>

Hi @formicheedintorni,

How have you solved the problem?  
I am stuck at the same point, any advice would be really appreciated.

Thanks,  
Burc

---

<div class="post-metadata">

**Author:** ![burc](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@burc](https://forum.keycloak.org/u/burc)\
**Post date:** [March 1, 2021, 12:46pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/11 "2021-03-01T12:46:14Z")

</div>

> [@formicheedintorni](#):
>
> 16927:2020-03-16 12:15:48,621 WARN [org.keycloak.events] (default task-760) type=LOGIN\_ERROR, realmId=test, clientId=null, userId=null, ipAddress=…, error=invalid\_code

Hi All,

I have overcome the following error by adding Keycloak URL to trusted sites in the security settings of internet explorer. I hope it can help someone who faces the same issue.

16927:2020-03-16 12:15:48,621 WARN [org.keycloak.events] (default task-760) type=LOGIN\_ERROR, realmId=test, clientId=null, userId=null, ipAddress=…, error=invalid\_code

Kind Regards,  
Burchan

---

<div class="post-metadata">

**Author:** ![gardellajuanpablo](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/gardellajuanpablo/32/2952_2.png) [@gardellajuanpablo](https://forum.keycloak.org/u/gardellajuanpablo)\
**Post date:** [April 23, 2021, 7:30pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/12 "2021-04-23T19:30:14Z")

</div>

The issue I had was using [https://foo.com:443/auth](https://foo.com:443/auth) as KEYCLOAK\_FRONTEND\_URL. Replacing by [https://foo.com/auth](https://foo.com/auth) fixes the problem.

---

<div class="post-metadata">

**Author:** ![geetha](https://avatars.discourse-cdn.com/v4/letter/g/f08c70/32.png) [@geetha](https://forum.keycloak.org/u/geetha)\
**Post date:** [March 26, 2024, 10:37am UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/14 "2024-03-26T10:37:38Z")

</div>

Hi,  
I cannot log in keycloak. I found in the log file this error:

2024-03-26 15:56:21,009 WARN [org.keycloak.events] (executor-thread-25) type=“LOGIN\_ERROR”, realmId=“48f8dcbb-5a63-46ce-8a1e-93cd184f7ea9”, clientId=“SpringBootDev”, userId=“null”, ipAddress=“…”, error=“user\_not\_found”, auth\_method=“openid-connect”, auth\_type=“code”

I can’t find a solution by google  
Does anyone have an idea?  
Thanks,  
Geetha

---

<div class="post-metadata">

**Author:** ![Armeice](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/armeice/32/10363_2.png) [@Armeice](https://forum.keycloak.org/u/Armeice)\
**Post date:** [May 7, 2024, 9:58pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/15 "2024-05-07T21:58:03Z")

</div>

Hello guys. I still have this problem:

WARN [org.keycloak.events] (executor-thread-319) type=“LOGIN\_ERROR”, realmId=“XXX”, clientId=“XXX”, userId=“null”, ipAddress=“XXX”, error=“invalid\_user\_credentials”, auth\_method=“openid-connect”, auth\_type=“code”, response\_type=“token”

but when I generate the link (redirect happen after link click) it has both client\_id (and in fact it appears in the log) but also user\_id (but strangely it is null). Does anyone have any ideas?

---

<div class="post-metadata">

**Author:** ![TaridaGeorge](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/taridageorge/32/10384_2.png) [@TaridaGeorge](https://forum.keycloak.org/u/TaridaGeorge)\
**Post date:** [May 9, 2024, 4:47pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/16 "2024-05-09T16:47:05Z")

</div>

Hello, guys! Please check to see if theres any problems with the Cookies. You may have samesite=strict cookie policy set and if you try to login from within an iframe that will not work.

---

<div class="post-metadata">

**Author:** ![Guruvel](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Guruvel](https://forum.keycloak.org/u/Guruvel)\
**Post date:** [July 16, 2024, 1:44pm UTC](https://forum.keycloak.org/t/login-error-clientid-null-userid-null-error-invalid-code/1714/17 "2024-07-16T13:44:52Z")

</div>

Hi @TaridaGeorge ,

Where I have to set this settings . in keycloak or browser?

thanks.
