You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//============= Config [Edit these with your settings] =====================
12
-
internalconststringvstsCollectionUrl="https://myaccount.visualstudio.com";//change to the URL of your VSTS account; NOTE: This must use HTTPS
13
-
internalconststringclientId="872cd9fa-d31f-45e0-9eab-6e460a02d1f1";//update this with your Application ID from step 2.6 (do not change this if you have an MSA backed account)
For a headless text output client application, it is not possible authenticate through an interactive prompt. Instead a text only approach is necessary. This flow leverages a user's external device (i.e. phone) to authenticate through an interactive login prompt and pass the auth token to the headless application. For more information [click here](https://azure.microsoft.com/en-us/resources/samples/active-directory-dotnet-deviceprofile/?v=17.23h).
3
+
For a headless text output client application, it is not possible authenticate through an interactive prompt. Instead a text only approach is necessary. This flow leverages a user's external device (i.e. phone) to authenticate through an interactive login prompt and pass the auth token to the headless application. For more information [click here](https://azure.microsoft.com/resources/samples/active-directory-dotnet-deviceprofile/?v=17.23h).
4
+
5
+
If the tenant admin requires device authentication conditional access policies, using the Device profile flow won't be a good option.
4
6
5
7
## Sample Application
6
8
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.
9
+
This sample will walk you through the steps to create a client-side console application which uses **MSAL.NET** to authenticate a user via the [Device Profile flow](https://azure.microsoft.com/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.
10
+
11
+
To run this sample you will need:
8
12
9
-
To run this sample for an [Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory/active-directory-whatis) backed Azure DevOps account you will need:
10
-
*[Visual Studio IDE](https://www.visualstudio.com/vs/)
11
-
* An Azure Active Directory (AAD) tenant. If you do not have one, follow these [steps to set up an AAD](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-howto-tenant)
12
-
* A user account in your AAD tenant
13
-
* A Azure DevOps account backed by your AAD tenant where your user account has access. If you have an existing Azure DevOps account not connected to your AAD tenant follow these [steps to connect your AAD tenant to your Azure DevOps account](https://www.visualstudio.com/en-us/docs/setup-admin/team-services/manage-organization-access-for-your-account-vs)
- An **Azure AD** tenant. For more information see: [How to get an Azure AD tenant](https://docs.microsoft.com/azure/active-directory/develop/quickstart-create-new-tenant)
15
+
- A user account in your **Azure AD** tenant.
16
+
- A Azure DevOps account backed by your AAD tenant where your user account has access. If you have an existing Azure DevOps account not connected to your AAD tenant follow these [steps to connect your AAD tenant to your Azure DevOps account](https://docs.microsoft.com/azure/devops/organizations/accounts/manage-azure-active-directory-groups-vsts?view=vsts&tabs=new-nav)
14
17
15
18
To run this sample for a [Microsoft Account](https://account.microsoft.com/account) backed Azure DevOps account you will need:
16
-
*[Visual Studio IDE](https://www.visualstudio.com/vs/)
17
-
* A Azure DevOps account not connected to AAD
18
19
19
-
## Step 1: Clone or download vsts-auth-samples repository
If you are a Microsoft Account backed Azure DevOps account please skip this step.
30
34
```
31
35
32
-
1. Sign in to the [Azure Portal](https://portal.azure.com).
33
-
2. On the top bar, click on your account and under the Directory list, choose the Active Directory tenant where you wish to register your application.
34
-
3. On the left hand navigation menu, select `Azure Active Directory`.
35
-
4. Click on `App registrations` and select `New application registration` from the top bar.
36
-
5. Enter a `name` for you application, ex. "Adal native app sample", choose `Native` for `application type`, and enter `http://adalsample` for the `Redirect URI`. Finally click `create` at the bottom of the screen.
37
-
6. Save the `Application ID` from your new application registration. You will need it later in this sample.
38
-
7. Grant permissions for Azure DevOps. Click `Required permissions` -> `add` -> `1 Select an API` -> type in and select `Azure DevOps` -> check the box for `Delegated Permissions` -> click `Select` -> click `Done` -> click `Grant Permissions` -> click `Yes`.
36
+
1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
37
+
1. Select **New registration**.
38
+
1. In the **Register an application page** that appears, enter your application's registration information:
39
+
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `MSAL-DeviceCodeFlow`.
40
+
- Under **Supported account types**, select **Accounts in this organizational directory only**.
41
+
1. Select **Register** to create the application.
42
+
1. In the app's registration screen, find and note the **Application (client) ID**. You use this value in your app's configuration file(s) later in your code.
43
+
- In the **Advanced settings** | **Default client type** section, flip the switch for `Treat application as a public client` to **Yes**.
44
+
1. Select **Save** to save your changes.
45
+
1. In the app's registration screen, select the **API permissions** blade in the left to open the page where we add access to the APIs that your application needs.
46
+
- Select the **Add a permission** button and then,
47
+
- Ensure that the **Microsoft APIs** tab is selected.
48
+
- In the list of APIs, select the API `Azure DevOps`.
49
+
- In the **Delegated permissions** section, select the **user_impersonation** in the list. Use the search box if necessary.
50
+
- Select the **Add permissions** button at the bottom.
51
+
52
+
## Step 3: Configure the application to use your app registration
39
53
40
-
## Step 3: Install and configure ADAL (optional)
54
+
Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.
41
55
42
-
Package: `Microsoft.Identity.Model.Clients.ActiveDirectory` has already been installed and configured in the sample, but if you are adding to your own project you will need to [install and configure it yourself](https://www.nuget.org/packages/Microsoft.IdentityModel.Clients.ActiveDirectory).
56
+
> In the steps below, "ClientID" is the same as "Application ID" or "AppId".
43
57
44
-
## Step 4a: Run the sample (AAD backed Azure DevOps account)
58
+
1. Open the `DeviceProfileSample\App.config` file.
59
+
1. Find the key `ida:ClientID` and replace the existing value with the application ID (clientId) of `ManagedClientConsoleAppSample` app copied from the Azure portal.
60
+
1. Find the key `ida:Tenant` and replace the existing value with your Azure AD tenant ID or tenant domain.
61
+
1. Find the key `ado:OrganizationUrl` and replace the existing value to the URL of your Azure DevOps organization; NOTE: This must use HTTPS.
45
62
46
-
1. Navigate to the sample in cloned repo `vsts-auth-samples/DeviceProfileSample/`
47
-
2. Open the solution file `DeviceProfileSample.sln` in [Visual Studio 2017](https://www.visualstudio.com/downloads/)
48
-
3. Use [Nuget package restore](https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore) to ensure you have all dependencies installed
49
-
4. Open CS file `Program.cs` and there is a section with input values to change at the top of the class:
50
-
*`azureDevOpsOrganizationUrl` - Update this value to your VSTS collection URL, e.g. http://dev.azure.com/organization.
51
-
*`clientId` - Update this value with the `Application ID` you saved in step 2.6.
52
-
5. Build and run solution. You should see a console window with instructions 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.
63
+
## Running the sample
53
64
54
-
## Step 4b: Run the sample (Microsoft Account backed Azure DevOps account)
65
+
Clean the solution, rebuild the solution, and run it.
55
66
56
-
1. Navigate to the sample in cloned repo `vsts-auth-samples/DeviceProfileSample/`
57
-
2. Open the solution file `DeviceProfileSample.sln` in [Visual Studio 2017](https://www.visualstudio.com/downloads/)
58
-
3. Use [Nuget package restore](https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore) to ensure you have all dependencies installed
59
-
4. Open CS file `Program.cs` and there is a section with input values to change at the top of the class:
60
-
*`azureDevOpsOrganizationUrl` - Update this value to your VSTS collection URL, e.g. http://dev.azure.com/organization.
61
-
5. Build and run solution. You should see a console window with instructions 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.
67
+
Use a web browser to open the Url (https://microsoft.com/devicelogin) that is displayed in console app. Input the code presented in the console , sign-in and check the result of the operation back in the console.
0 commit comments