0
votes

I am working on a project where I have a requirement to create workitem on Visual Studio Online instance. I am using personal access token. This will set CreatedBy as my name (Expected behavior). I am considering to use Oauth2; However, I am not sure if there's the way to do this Server-to-Server (Non-Interactive)? Any suggestions thoughts?


            var personalAccessToken = "PAT Value fro Config";
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))));

            return client;


PAT's are created in Security context of the user. I need to find a way to use Oauth without having to involved UI. So I'm looking for Server-to-Server Auth.

object[] patchDocument = new object[5];
            patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = bugTitle };
            patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = bugReproSteps };
            patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" };
            patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" };
            patchDocument[4] = new { op = "add", path = "/fields/System.IterationPath", value = deserializeIteration };
            //System.IterationPath
            string postUrl = $"{_vsoInstanceUrl}/DefaultCollection/ProjectName/_apis/wit/workitems/$Bug?api-version=1.0";
await ExecutePatch(patchDocument.ToArray(), postUrl, "application/json-patch+json");
1
Your best bet is to research this (asking a Q here is not really research because of how it works) and try some things. Come back with some code and your results if you run into problems. stackoverflow.com/help/how-to-ask - user1531971

1 Answers

0
votes

No there is no Server-to-Server OAuth support. If you use the .NET Client Object Model you can leverage Impersonation support.

If your account has "Act on behalf of others" permissions you can also achieve a "User X via YourAccount".