Azure REST API Returns 200 for me and 203 for other users

122 Views Asked by At

I'm creating an app and need the information about the user projects. When I request that for me, a administrator in the organization, the request goes without a problem. When other users request something it gives the 203 code.

I'm using the following code:

  var personalaccesstoken = token;

            using var client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                Convert.ToBase64String(
                    Encoding.ASCII.GetBytes(
                       $@"{""}:{personalaccesstoken}")));
             using var response = await client.GetAsync(
                "https://dev.azure.com/{organization}/_apis/projects?api-version=2.0");
            response.EnsureSuccessStatusCode();
            var responseBody = await response.Content.ReadAsStringAsync();

I'm using Oauth to get the token. Does anyone know why this is not working?

1

There are 1 best solutions below

0
On

The 203 error code normally caused by an incorrect PAT format. Looks like you are probably failing authentication because the PAT did not be encoded with base64 correctly.

You need to ask the users to check the PAT in their code to see whether it is correct, or generate a new PAT and replace it in the code to see whether the issue would be fixed.