Skip to content

Commit 20119cf

Browse files
committed
updated the device profile sample to remove bloat code
1 parent da9626d commit 20119cf

File tree

6 files changed

+19
-41
lines changed

6 files changed

+19
-41
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26228.9
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Device Profile Get Identity Data", "Device Profile Get Identity Data.csproj", "{3221E66C-4C5B-4EAD-A5BE-DA88A9AC3A34}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Device Profile sample", "Device Profile sample.csproj", "{3221E66C-4C5B-4EAD-A5BE-DA88A9AC3A34}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Device_Profile_Sample/Device_Profile_Get_Identity_Data/Program.cs renamed to Device_Profile_Sample/Program.cs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,26 @@
99
using System.Text;
1010
using System.Threading.Tasks;
1111

12-
namespace DeviceProfileGetIdentityData
12+
namespace DeviceProfileSample
1313
{
1414
public class Program
1515
{
1616
public const string resource_vsts = "499b84ac-1321-427f-aa17-267ca6975798";
1717
public const string clientId_vs = "872cd9fa-d31f-45e0-9eab-6e460a02d1f1";
1818
public static void Main(string[] args)
1919
{
20-
string commandString = string.Empty;
21-
Console.ForegroundColor = ConsoleColor.Blue;
22-
Console.WriteLine("***********************************************************");
23-
Console.WriteLine("* Get User Identity Data *");
24-
Console.WriteLine("* *");
25-
Console.WriteLine("* *");
26-
Console.WriteLine("* *");
27-
Console.WriteLine("***********************************************************");
28-
Console.WriteLine("");
20+
//============= Config [Edit these with your settings] =====================
21+
var vstsAccountUri = "https://mseng.VisualStudio.com";
22+
var restEndpoint = "_apis/projects?api-version=2.0";
23+
//==========================================================================
2924

30-
// main command cycle
31-
while (!commandString.Equals("Exit"))
32-
{
33-
Console.ResetColor();
34-
Console.WriteLine("Enter command (userdata | exit) >");
35-
commandString = Console.ReadLine();
25+
UserData(vstsAccountUri,restEndpoint);
3626

37-
switch (commandString.ToUpper())
38-
{
39-
case "USERDATA":
40-
UserData();
41-
break;
42-
case "EXIT":
43-
Console.WriteLine("Bye!");
44-
return;
45-
break;
46-
default:
47-
Console.ForegroundColor = ConsoleColor.Red;
48-
Console.WriteLine("Invalid command.");
49-
break;
50-
}
51-
}
27+
//prevents console from closing immediately at the end of output
28+
Console.ReadLine();
5229
}
5330

54-
static void UserData()
31+
static void UserData(string vstsAccountUri, string restEndpoint)
5532
{
5633
//get auth token
5734
AuthenticationResult result = GetToken(null);
@@ -60,15 +37,15 @@ static void UserData()
6037
//call VSTS REST API
6138
using (var client = new HttpClient())
6239
{
63-
client.BaseAddress = new Uri("https://app.vssps.visualstudio.com");
40+
client.BaseAddress = new Uri(vstsAccountUri);
6441
client.DefaultRequestHeaders.Accept.Clear();
6542
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
6643
client.DefaultRequestHeaders.Add("User-Agent", "VstsRestApiSamples");
6744
client.DefaultRequestHeaders.Add("X-TFS-FedAuthRedirect", "Suppress");
6845
client.DefaultRequestHeaders.Authorization = authHeader;
6946

7047
//connect to REST endpoint
71-
HttpResponseMessage response = client.GetAsync("_apis/connectiondata").Result;
48+
HttpResponseMessage response = client.GetAsync(restEndpoint).Result;
7249

7350
if (response.IsSuccessStatusCode)
7451
{

Device_Profile_Sample/Device_Profile_Get_Identity_Data/README.md renamed to Device_Profile_Sample/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ For a headless text output client application, it is not possible authenticate t
44

55
## Sample Application
66

7-
This buildable sample will walk you through the steps to create a client-side console application which uses ADAL to authenticate a user via the [Device Profile flow](https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-deviceprofile/?v=17.23h) and returns a JSON string containing all VSTS identity data for the authenticated user.
7+
This buildable sample will walk you through the steps to create a client-side console application which uses ADAL to authenticate a user via the [Device Profile flow](https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-deviceprofile/?v=17.23h) and returns a JSON string containing all account team project data viewable by the authenticated user.
88

99
## Step 1: Clone or download vsts-auth-samples repository
1010

@@ -19,11 +19,12 @@ Package: `Microsoft.Identity.Model.Clients.ActiveDirectory` has already been ins
1919

2020
## Step 3: Run the sample
2121

22-
1. Navigate to the sample in cloned repo `vsts-auth-samples/Device_Profile_Sample/Device_Profile_Get_Identity_Data/`
22+
1. Navigate to the sample in cloned repo `vsts-auth-samples/Device_Profile_Sample/`
2323
2. Use [Nuget package restore](https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore) to ensure you have all dependencies installed
24-
3. Open the solution file `Device Profile - Get Identity Data.sln` in [Visual Studio IDE 2017](https://www.visualstudio.com/downloads/)
24+
3. Open the solution file `Device Profile Sample.sln` in [Visual Studio IDE 2017](https://www.visualstudio.com/downloads/)
2525
4. Open CS file `Program.cs` and there are 2 important fields to be aware of:
2626
* `VSTSResourceId` - Immutable value. Denotes that we need a VSTS access token.
2727
* `clientId` - Immutable value*. *Normally your app's registered AAD clientId, but for VSTS is must be the VS client ID provided
28-
These fields are how we configure ADAL to aquire a VSTS access token for the authenticated user.
29-
5. Build and run solution. You should see a console window waiting for text input. Input `userdata` to start the Device Profile auth flow. After authenticating you should see VSTS identity information displayed in the console window.
28+
* `vstsAccountUri` - Mutable value. Denotes your vsts account URL (i.e. https://myaccount.visualstudio.com). Please update this with your account URL
29+
* `restEndpoint` - Mutable value. Denotes which REST API endpoint we want to hit. We have configured it to return team project information.
30+
5. Build and run solution. You should see a console window with instruction on how to authenticate via the Device Profile flow. After authenticating you should see all team project information viewable by the authenticated identity displayed in the console window.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Learn more about [integrating with Team Services](https://www.visualstudio.com/d
99
## Samples
1010

1111
* [Managed Client ADAL Sample](./Managed_Client_ADAL_Sample/README.md)
12-
* [Device Profile Sample](./Device_Profile_Sample/Device_Profile_Get_Identity_Data/README.md)
12+
* [Device Profile Sample](./Device_Profile_Sample/README.md)
1313
* [ASP.NET Web App OAuth Sample](./ASP.NET_Web_App_OAuth_Sample/aspnet/README.md)
1414
* [Client Libraries Sample](./Client_Libraries_Sample/README.md)

0 commit comments

Comments
 (0)