@@ -106,97 +106,15 @@ Add the details of your app registration to the project.
106106
1071071. Create a file in the **GraphAppOnlyTutorial** directory named **Settings.cs** and add the following code.
108108
109- ```csharp
110- using Microsoft.Extensions.Configuration;
111-
112- namespace GraphAppOnlyTutorial;
113-
114- public class Settings
115- {
116- public string? ClientId { get; set; }
117-
118- public string? ClientSecret { get; set; }
119-
120- public string? TenantId { get; set; }
121-
122- public static Settings LoadSettings()
123- {
124- // Load settings
125- IConfiguration config = new ConfigurationBuilder()
126- /* appsettings.json is required */
127- .AddJsonFile("appsettings.json", optional: false)
128- /* appsettings.Development.json" is optional, values override appsettings.json */
129- .AddJsonFile($"appsettings.Development.json", optional: true)
130- /* User secrets are optional, values override both JSON files */
131- .AddUserSecrets<Program>()
132- .Build();
133-
134- return config.GetRequiredSection("Settings").Get<Settings>() ??
135- throw new Exception("Could not load app settings. See README for configuration instructions.");
136- }
137- }
138- ```
109+ :::code language="csharp" source="includes/dotnet/src/app-auth/GraphAppOnlyTutorial/Settings.cs" id="SettingsSnippet":::
139110
140111## Design the app
141112
142113Create a console-based menu.
143114
1441151. Open **./Program.cs** and replace its entire contents with the following code.
145116
146- ```csharp
147- using GraphAppOnlyTutorial;
148-
149- Console.WriteLine(".NET Graph App-only Tutorial\n");
150-
151- var settings = Settings.LoadSettings();
152-
153- // Initialize Graph
154- InitializeGraph(settings);
155-
156- int choice = -1;
157-
158- while (choice != 0)
159- {
160- Console.WriteLine("Please choose one of the following options:");
161- Console.WriteLine("0. Exit");
162- Console.WriteLine("1. Display access token");
163- Console.WriteLine("2. List users");
164- Console.WriteLine("3. Make a Graph call");
165-
166- try
167- {
168- choice = int.Parse(Console.ReadLine() ?? string.Empty);
169- }
170- catch (System.FormatException)
171- {
172- // Set to invalid value
173- choice = -1;
174- }
175-
176- switch (choice)
177- {
178- case 0:
179- // Exit the program
180- Console.WriteLine("Goodbye...");
181- break;
182- case 1:
183- // Display access token
184- await DisplayAccessTokenAsync();
185- break;
186- case 2:
187- // List users
188- await ListUsersAsync();
189- break;
190- case 3:
191- // Run any Graph code
192- await MakeGraphCallAsync();
193- break;
194- default:
195- Console.WriteLine("Invalid choice! Please try again.");
196- break;
197- }
198- }
199- ```
117+ :::code language="csharp" source="includes/dotnet/src/app-auth/GraphAppOnlyTutorial/Program.cs" id="ProgramSnippet":::
200118
2011191. Add the following placeholder methods at the end of the file. You implement them in later steps.
202120
0 commit comments