microsoft/azure-devops-extension-sdk

User ID from SDK.getAppToken() doesn't match the user ID from other Azure APIs

pelizza opened this issue · 3 comments

Hi there,

I use the following code to get the user token and validate their requests on the backend. This token has a user_id property that identifies the user:

import * as SDK from 'azure-devops-extension-sdk';
const token = await SDK.getAppToken();

Additionally, I use other methods to build user pickers and render user names on the screen such as:

import { getService } from 'azure-devops-extension-sdk';
import { IdentityServiceIds } from 'azure-devops-extension-api/Identities';

const identityService = await getService(IdentityServiceIds.IdentityService);
identityService.searchIdentitiesAsync(userId, ['user'], undefined, 'uid');
identityService.getIdentityMruAsync();
identityService.searchIdentitiesAsync(query, ['user']);

The problem is that the users returned by the methods above don’t have the same ID as the ID present in the appToken in some Azure DevOps instances. This causes a huge problem because I can’t find the logged-in user within the API query results, causing a lot of other issues.

The fun fact is that I have 3 Azure DevOps Services instances, in which I have the same set of users, and this problem only happens with some of these user/instance combinations.

@pelizza Did you find a solution? I'm fiddling with a similar problem on the server side. I want to match the user info from the AppToken to an AzDO user using the REST API. But I have not been able to find the correct endpoint, yet. I tried the identities section, the graph endpoint, user/member entitlements, etc.

Check connectionData endpoint.
#16

Closing as duplicate of #16. Thanks @altinoren for pointing that out!