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
In this quickstart, you download and run a code sample that demonstrates how a .NET Core console application can get an access token to call the Microsoft Graph API and display a [list of users](/graph/api/user-list) in the directory. The code sample also demonstrates how a job or a Windows service can run with an application identity, instead of a user's identity. The sample console application in this quickstart is also a daemon application, so it's a confidential client application.
22
22
23
-
> [!div renderon="docs"]
24
-
> The following diagram shows how the sample app works:
25
-
>
26
-
> 
27
-
>
28
-
29
23
## Prerequisites
30
24
31
25
This quickstart requires [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download) but will also work with .NET 5.0 SDK.
32
26
33
-
> [!div renderon="docs"]
34
-
> ## Register and download the app
35
-
36
-
> [!div renderon="docs" class="sxs-lookup"]
37
-
>
38
-
> You have two options to start building your application: automatic or manual configuration.
39
-
>
40
-
> ### Automatic configuration
41
-
>
42
-
> If you want to register and automatically configure your app and then download the code sample, follow these steps:
43
-
>
44
-
> 1. Go to the <ahref="https://portal.azure.com/?Microsoft_AAD_RegisteredApps=true#blade/Microsoft_AAD_RegisteredApps/applicationsListBlade/quickStartType/DotNetCoreDaemonQuickstartPage/sourceType/docs"target="_blank">Azure portal page for app registration</a>.
45
-
> 1. Enter a name for your application and select **Register**.
46
-
> 1. Follow the instructions to download and automatically configure your new application in one click.
47
-
>
48
-
> ### Manual configuration
49
-
>
50
-
> If you want to manually configure your application and code sample, use the following procedures.
51
-
>
52
-
> [!div renderon="docs"]
53
-
> #### Step 1: Register your application
54
-
> To register your application and add the app's registration information to your solution manually, follow these steps:
55
-
>
56
-
> 1. Sign in to the <ahref="https://portal.azure.com/"target="_blank">Azure portal</span></a>.
57
-
> 1. If you have access to multiple tenants, use the **Directories + subscriptions** filter :::image type="icon" source="./media/common/portal-directory-subscription-filter.png" border="false"::: in the top menu to switch to the tenant in which you want to register the application.
58
-
> 1. Search for and select **Azure Active Directory**.
59
-
> 1. Under **Manage**, select **App registrations** > **New registration**.
60
-
> 1. For **Name**, enter a name for your application. For example, enter **Daemon-console**. Users of your app will see this name, and you can change it later.
61
-
> 1. Select **Register** to create the application.
62
-
> 1. Under **Manage**, select **Certificates & secrets**.
63
-
> 1. Under **Client secrets**, select **New client secret**, enter a name, and then select **Add**. Record the secret value in a safe location for use in a later step.
64
-
> 1. Under **Manage**, select **API Permissions** > **Add a permission**. Select **Microsoft Graph**.
65
-
> 1. Select **Application permissions**.
66
-
> 1. Under the **User** node, select **User.Read.All**, and then select **Add permissions**.
67
-
68
-
> [!div class="sxs-lookup" renderon="portal"]
69
-
> ### Download and configure your quickstart app
70
-
>
71
-
> #### Step 1: Configure your application in the Azure portal
72
-
> For the code sample in this quickstart to work, create a client secret and add the Graph API's **User.Read.All** application permission.
> #### Step 3: Configure your Visual Studio project
100
-
>
101
-
> 1. Extract the .zip file to a local folder that's close to the root of the disk. For example, extract to *C:\Azure-Samples*.
102
-
>
103
-
> We recommend extracting the archive into a directory near the root of your drive to avoid errors caused by path length limitations on Windows.
104
-
>
105
-
> 1. Open the solution in Visual Studio: *1-Call-MSGraph\daemon-console.sln* (optional).
106
-
> 1. In *appsettings.json*, replace the values of `Tenant`, `ClientId`, and `ClientSecret`:
107
-
>
108
-
> ```json
109
-
> "Tenant": "Enter_the_Tenant_Id_Here",
110
-
> "ClientId": "Enter_the_Application_Id_Here",
111
-
> "ClientSecret": "Enter_the_Client_Secret_Here"
112
-
> ```
113
-
> In that code:
114
-
> - `Enter_the_Application_Id_Here` is the application (client) ID for the application that you registered.
115
-
To find the values for the application (client) ID and the directory (tenant) ID, go to the app's **Overview** page in the Azure portal.
116
-
> - Replace `Enter_the_Tenant_Id_Here` with the tenant ID or tenant name (for example, `contoso.microsoft.com`).
117
-
> - Replace `Enter_the_Client_Secret_Here` with the client secret that you created in step 1.
118
-
To generate a new key, go to the **Certificates & secrets** page.
119
-
120
-
> [!div class="sxs-lookup" renderon="portal"]
121
-
> #### Step 3: Admin consent
122
-
123
-
> [!div renderon="docs"]
124
-
> #### Step 4: Admin consent
51
+
> [!div class="sxs-lookup"]
52
+
53
+
#### Step 3: Admin consent
125
54
126
55
If you try to run the application at this point, you'll receive an *HTTP 403 - Forbidden* error: "Insufficient privileges to complete the operation." This error happens because any app-only permission requires a global administrator of your directory to give consent to your application. Select one of the following options, depending on your role.
127
56
128
57
##### Global tenant administrator
129
58
130
-
> [!div renderon="docs"]
131
-
> If you're a global tenant administrator, go to **Enterprise applications** in the Azure portal. Select your app registration, and select **Permissions** from the **Security** section of the left pane. Then select the large button labeled **Grant admin consent for {Tenant Name}** (where **{Tenant Name}** is the name of your directory).
132
-
133
-
> [!div renderon="portal" class="sxs-lookup"]
59
+
> [!div class="sxs-lookup"]
134
60
> If you're a global administrator, go to the **API Permissions** page and select **Grant admin consent for Enter_the_Tenant_Name_Here**.
135
61
> > [!div id="apipermissionspage"]
136
62
> > [Go to the API Permissions page]()
@@ -143,18 +69,9 @@ If you're a standard user of your tenant, ask a global administrator to grant ad
> * Replace `Enter_the_Tenant_Id_Here` with the tenant ID or tenant name (for example, `contoso.microsoft.com`).
149
-
> *`Enter_the_Application_Id_Here` is the application (client) ID for the application that you registered.
150
-
151
72
You might see the error "AADSTS50011: No reply address is registered for the application" after you grant consent to the app by using the preceding URL. This error happens because this application and the URL don't have a redirect URI. You can ignore it.
152
73
153
-
> [!div class="sxs-lookup" renderon="portal"]
154
-
> #### Step 4: Run the application
155
-
156
-
> [!div renderon="docs"]
157
-
> #### Step 5: Run the application
74
+
#### Step 4: Run the application
158
75
159
76
If you're using Visual Studio or Visual Studio for Mac, press **F5** to run the application. Otherwise, run the application via command prompt, console, or terminal:
160
77
@@ -172,10 +89,10 @@ This quickstart application uses a client secret to identify itself as a confide
172
89
## More information
173
90
This section gives an overview of the code required to sign in users. This overview can be useful to understand how the code works, what the main arguments are, and how to add sign-in to an existing .NET Core console application.
174
91
175
-
> [!div class="sxs-lookup" renderon="portal"]
176
-
> ### How the sample works
177
-
>
178
-
> 
92
+
> [!div class="sxs-lookup"]
93
+
### How the sample works
94
+
95
+

In this quickstart, you download and run a code sample that demonstrates how a Python application can get an access token using the app's identity to call the Microsoft Graph API and display a [list of users](/graph/api/user-list) in the directory. The code sample demonstrates how an unattended job or Windows service can run with an application identity, instead of a user's identity.
21
21
22
-
> [!div renderon="docs"]
23
-
> 
24
-
25
22
## Prerequisites
26
23
27
24
To run this sample, you need:
28
25
29
26
-[Python 2.7+](https://www.python.org/downloads/release/python-2713) or [Python 3+](https://www.python.org/downloads/release/python-364/)
> You have two options to start your quickstart application: Express (Option 1 below), and Manual (Option 2)
38
-
>
39
-
> ### Option 1: Register and auto configure your app and then download your code sample
40
-
>
41
-
> 1. Go to the <ahref="https://portal.azure.com/?Microsoft_AAD_RegisteredApps=true#blade/Microsoft_AAD_RegisteredApps/applicationsListBlade/quickStartType/PythonDaemonQuickstartPage/sourceType/docs"target="_blank">Azure portal - App registrations</a> quickstart experience.
42
-
> 1. Enter a name for your application and select **Register**.
43
-
> 1. Follow the instructions to download and automatically configure your new application with just one click.
44
-
>
45
-
> ### Option 2: Register and manually configure your application and code sample
46
-
47
-
> [!div renderon="docs"]
48
-
> #### Step 1: Register your application
49
-
> To register your application and add the app's registration information to your solution manually, follow these steps:
50
-
>
51
-
> 1. Sign in to the <ahref="https://portal.azure.com/"target="_blank">Azure portal</a>.
52
-
> 1. If you have access to multiple tenants, use the **Directories + subscriptions** filter :::image type="icon" source="./media/common/portal-directory-subscription-filter.png" border="false"::: in the top menu to switch to the tenant in which you want to register the application.
53
-
> 1. Search for and select **Azure Active Directory**.
54
-
> 1. Under **Manage**, select **App registrations** > **New registration**.
55
-
> 1. Enter a **Name** for your application, for example `Daemon-console`. Users of your app might see this name, and you can change it later.
56
-
> 1. Select **Register**.
57
-
> 1. Under **Manage**, select **Certificates & secrets**.
58
-
> 1. Under **Client secrets**, select **New client secret**, enter a name, and then select **Add**. Record the secret value in a safe location for use in a later step.
59
-
> 1. Under **Manage**, select **API Permissions** > **Add a permission**. Select **Microsoft Graph**.
60
-
> 1. Select **Application permissions**.
61
-
> 1. Under **User** node, select **User.Read.All**, then select **Add permissions**.
62
-
63
-
> [!div class="sxs-lookup" renderon="portal"]
64
-
> ### Download and configure the quickstart app
65
-
>
66
-
> #### Step 1: Configure your application in Azure portal
67
-
> For the code sample in this quickstart to work, create a client secret and add Graph API's **User.Read.All** application permission.
> - `Enter_the_Application_Id_Here` - is the **Application (client) ID** for the application you registered.
101
-
> - `Enter_the_Tenant_Id_Here` - replace this value with the **Tenant Id** or **Tenant name** (for example, contoso.microsoft.com)
102
-
> - `Enter_the_Client_Secret_Here` - replace this value with the client secret created on step 1.
103
-
>
104
-
> > [!TIP]
105
-
> > To find the values of **Application (client) ID**, **Directory (tenant) ID**, go to the app's **Overview** page in the Azure portal. To generate a new key, go to **Certificates & secrets** page.
106
-
107
-
> [!div class="sxs-lookup" renderon="portal"]
108
-
> #### Step 3: Admin consent
109
-
110
-
> [!div renderon="docs"]
111
-
> #### Step 4: Admin consent
49
+
#### Step 3: Admin consent
112
50
113
51
If you try to run the application at this point, you'll receive *HTTP 403 - Forbidden* error: `Insufficient privileges to complete the operation`. This error happens because any *app-only permission* requires Admin consent: a global administrator of your directory must give consent to your application. Select one of the options below depending on your role:
114
52
115
53
##### Global tenant administrator
116
54
117
-
> [!div renderon="docs"]
118
-
> If you are a global tenant administrator, go to **API Permissions** page in **App registrations** in the Azure portal and select **Grant admin consent for {Tenant Name}** (Where {Tenant Name} is the name of your directory).
119
-
120
-
> [!div renderon="portal" class="sxs-lookup"]
55
+
> [!div class="sxs-lookup"]
121
56
> If you are a global administrator, go to **API Permissions** page select **Grant admin consent for Enter_the_Tenant_Name_Here**.
122
57
> > [!div id="apipermissionspage"]
123
58
> > [Go to the API Permissions page]()
@@ -130,17 +65,9 @@ If you're a standard user of your tenant, ask a global administrator to grant ad
0 commit comments