Git push on Bitbucket (applink to Jira) fails on user not associated with the token

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Problem

Jira is linked with Bitbucket, but push request fails for a specific user on pre-receive hook. This happens if Bitbucket cannot authenticate the user in Jira. This will cause the features of the Application Link to fail. The Bitbucket push gets the error that the "pre-receive hook declined", We can see the error in Bitbucket logs:

1 2 3 4 5 6 7 2022-06-20 09:56:21,510 ERROR [hook-callback:thread-2] <username> *H16ONUx596x4063936x13 6aanep 10.126.248.16 SSH - git-receive-pack '/om/omnihub-baseline.git' c.i.s.plugin.jira.JiraServiceImpl response com.atlassian.sal.api.net.ResponseStatusException: Unexpected response received. Status code: 500 at com.atlassian.applinks.core.auth.ApplicationLinksStringReturningResponseHandler.handle(ApplicationLinksStringReturningResponseHandler.java:16) at com.atlassian.applinks.core.auth.ApplicationLinksStringReturningResponseHandler.handle(ApplicationLinksStringReturningResponseHandler.java:13) at com.atlassian.applinks.oauth.auth.OAuthApplinksReturningResponseHandler.handle(OAuthApplinksReturningResponseHandler.java:50) at com.atlassian.sal.core.net.HttpClientRequest.executeAndReturn(HttpClientRequest.java:102) ...

We can see this is because of an error status 500 from Jira, and the following error appears in the atlassian-jira.log:

1 2 3 4 5 6 2022-06-21 17:03:22,818+0200 http-nio-8080-exec-1 ERROR anonymous 1023x1204342x11 - 62.128.7.33 /rest/api/2/search [c.a.o.serviceprovider.internal.AuthenticatorImpl] Failed to validate OAuth message com.atlassian.cache.CacheException: com.atlassian.oauth.serviceprovider.InvalidTokenException: Token 'XIUnPN1Qc982jufnQypngok5IBWqoIWu' is an access token, but has no user associated with it at com.atlassian.cache.ehcache.DelegatingCache.get(DelegatingCache.java:113) at com.atlassian.jira.cache.DeferredReplicationCache.get(DeferredReplicationCache.java:48) at com.atlassian.jira.oauth.serviceprovider.CachingServiceProviderTokenStore.get(CachingServiceProviderTokenStore.java:81) ...

Diagnosis

Diagnostic Steps

Run the following query and look for a row containing the consumer_key from the Jira error. This row should be deleted as the token fails to authenticate,

1 2 3 4 5 6 select * from oauthconsumertoken where token='XIUnPN1Qc982jufnQypngok5IBWqoIWu';   id | created | token_key | token | token_secret | token_type | consumer_key -------+----------------------------+--------------------------------------------------+----------------------------------+----------------------------------+------------+------------------------------------------- 10309 | 2015-07-01 19:35:59.842+00 | a5f05bf0-3feb-3479-b101-d5ac9e8ea56d:user1 | XIUnPN1Qc982jufnQypngok5IBWqoIWu | FM2lRWLrOHhXLdYwJtwwFI4SO3aftiQV | ACCESS | jira:2225f1ed-e21b-4ada-a40e-3ad49c79d7b4 (1 row)

Additionally there is a row for the user in the oauthsptoken table which should be deleted as well.

Cause

This is caused by a stale consumer key being used and can occur after a user migration.

Solution

Resolution

  1. Stop JIRA

  2. Create a backup of the JIRA database

  3. Using the consumer_key from above and the user key, run the following queries:

    1 2 delete from oauthconsumertoken where consumer_key = 'jira:2225f1ed-e21b-4ada-a40e-3ad49c79d7b4'; delete from oauthsptoken where consumer_key like 'Bitbucket%' and username=<user_key>;
  4. Start JIRA

Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.

Updated on April 2, 2025

Still need help?

The Atlassian Community is here for you.