An error message "User Lookup Failed" appears on integrating Xcode with Bitbucket Data Center
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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:
While adding a Bitbucket server account in Xcode, an error message "User Lookup Failed" pops up.
Environment:
- Bitbucket Data Center - 8.9.7
- Xcode - 15
Diagnosis:
The
atlassian-bitbucket.log
will have the following error stack trace:2024-01-23 11:01:44,357 DEBUG [http-nio-7990-exec-5 url: /rest/api/1.0/application-properties] @IH7EH9x661x117x0 10.211.XX.X "GET /rest/api/1.0/application-properties HTTP/1.1" c.a.b.i.c.s.CrowdSsoAuthenticationHandler Skipping Crowd SSO as it is not enabled 2024-01-23 11:01:44,357 DEBUG [http-nio-7990-exec-5 url: /rest/api/1.0/application-properties] @IH7EH9x661x117x0 10.211.XX.X "GET /rest/api/1.0/application-properties HTTP/1.1" c.a.s.i.a.DefaultAuthenticationService user1@example.com: Authenticator 'com.atlassian.bitbucket.server.bitbucket-crowd-sso:crowdSsoAuthHandler' opted out 2024-01-23 11:01:44,357 DEBUG [http-nio-7990-exec-5 url: /rest/api/1.0/application-properties] @IH7EH9x661x117x0 10.211.XX.X "GET /rest/api/1.0/application-properties HTTP/1.1" c.a.s.i.a.DefaultAuthenticationService user1@example.com: Authenticator 'com.atlassian.bitbucket.server.bitbucket-git-lfs:git-lfs-jwt-auth-handler' opted out 2024-01-23 11:01:44,401 DEBUG [http-nio-7990-exec-5 url: /rest/api/1.0/application-properties] @IH7EH9x661x117x0 10.211.XX.X "GET /rest/api/1.0/application-properties HTTP/1.1" c.a.s.i.user.DefaultUserService user1@example.com: User is active; updating cache 2024-01-23 11:01:44,406 DEBUG [http-nio-7990-exec-5 url: /rest/api/1.0/application-properties] @IH7EH9x661x117x0 10.211.XX.X "GET /rest/api/1.0/application-properties HTTP/1.1" c.a.s.i.a.DefaultAuthenticationService user1@example.com: Authenticator 'com.atlassian.bitbucket.server.bitbucket-access-tokens:accessTokenHttpAuthHandler' authenticated user1@example.com (3) 2024-01-23 11:01:44,437 DEBUG [http-nio-7990-exec-4 url: /rest/api/1.0/users/user1@example.com] @IH7EH9x661x118x0 10.211.XX.X "GET /rest/api/1.0/users/user1@example.com HTTP/1.1" c.a.b.i.c.s.CrowdSsoAuthenticationHandler Skipping Crowd SSO as it is not enabled 2024-01-23 11:01:44,437 DEBUG [http-nio-7990-exec-4 url: /rest/api/1.0/users/user1@example.com] @IH7EH9x661x118x0 10.211.XX.X "GET /rest/api/1.0/users/user1@example.com HTTP/1.1" c.a.s.i.a.DefaultAuthenticationService user1@example.com: Authenticator 'com.atlassian.bitbucket.server.bitbucket-crowd-sso:crowdSsoAuthHandler' opted out 2024-01-23 11:01:44,437 DEBUG [http-nio-7990-exec-4 url: /rest/api/1.0/users/user1@example.com] @IH7EH9x661x118x0 10.211.XX.X "GET /rest/api/1.0/users/user1@example.com HTTP/1.1" c.a.s.i.a.DefaultAuthenticationService user1@example.com: Authenticator 'com.atlassian.bitbucket.server.bitbucket-git-lfs:git-lfs-jwt-auth-handler' opted out 2024-01-23 11:01:44,452 DEBUG [http-nio-7990-exec-4 url: /rest/api/1.0/users/user1@example.com] @IH7EH9x661x118x0 10.211.XX.X "GET /rest/api/1.0/users/user1@example.com HTTP/1.1" c.a.s.i.user.DefaultUserService user1@example.com: Returning active from cache 2024-01-23 11:01:44,453 DEBUG [http-nio-7990-exec-4 url: /rest/api/1.0/users/user1@example.com] @IH7EH9x661x118x0 10.211.XX.X "GET /rest/api/1.0/users/user1@example.com HTTP/1.1" c.a.s.i.a.DefaultAuthenticationService user1@example.com: Authenticator 'com.atlassian.bitbucket.server.bitbucket-access-tokens:accessTokenHttpAuthHandler' authenticated user1@example.com (3) 2024-01-23 11:01:44,471 DEBUG [http-nio-7990-exec-4 url: /rest/api/1.0/users/user1@example.com; user: user1@example.com] user1@example.com @IH7EH9x661x118x0 10.211.XX.X "GET /rest/api/1.0/users/user1@example.com HTTP/1.1" c.a.s.i.r.e.ServiceExceptionMapper Mapping NoSuchUserException to REST response 404 - User user1@example.com does not exist.
- An error "User lookup Failed" will appear on the Xcode tool.
Cause:
- When a user adds a Bitbucket account, Xcode performs a user look-up using the "/rest/api/1.0/users/<user-name>" API, using the same username that the user entered in the login form. This API accepts a slug as input instead of a username, although if the username is simple and has no special characters, using a username in the API doesn't cause any issues because the username and slug could be identical in this scenario.
- The issue arises when a username contains special characters since the username and slug are likely to differ in this scenario. When a user is created in Bitbucket, the username is converted to a unique slug value and both may differ.
- In Bitbucket, user retrieval is done via the /rest/api/latest/users/{userSlug} API endpoint, where user slug is the only parameter used and is described in the API Doc.
- In this particular case, the username is the user1@example.com email address, which has the "@" sign. Thus, when this username was first created in Bitbucket, the "@" sign was changed to the "_" symbol to obtain the real slug value, which was then saved in the database.
- In this scenario, the true slug is user1_example.com, but Xcode does not transform the username into a slug before sending it to Bitbucket, thus the user lookup is performed using the username, user1@example.com. Because there is no user with the slug user1@example.com, Bitbucket sends Xcode a 404 HTTP response, which causes "User Lookup Failed" to show in Xcode.
The user details and distinction between username and slug are displayed in the manual execution of the same API that follows.
curl -s -u user1@example.com:<Token> http://10.211.XX.X:7990/rest/api/1.0/users/user1_example.com |jq "." { "name": "user1@example.com", "emailAddress": "user1@example.com", "active": true, "displayName": "user1@example.com", "id": 3, "slug": "user1_example.com", "type": "NORMAL", "links": { "self": [ { "href": "http://10.211.XX.X:7990/users/user1_example.com" } ] } }
Solution:
- The API used in Xcode to retrieve the user is not correct thus seek help from the product vendor of the Xcode tool to find a way to add the Bitbucket account in Xcode if the username and slug differ.