Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit 083c68d

Browse files
committed
Add license headers, move all configuration items to config
1 parent 15c5bd9 commit 083c68d

File tree

9 files changed

+134
-26
lines changed

9 files changed

+134
-26
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ There are two projects in this sample. Each needs to be separately registered i
9494

9595
#### Configure the TodoListClient project
9696

97-
1. Open `MainPage.xaml.cs'.
98-
2. Find the declaration of `tenant` and replace the value with the name of your Azure AD tenant.
99-
3. Find the declaration of `clientId` and replace the value with the Client ID from the Azure portal.
100-
4. Find the declaration of `todoListResourceId` and `todoListBaseAddress` and ensure their values are set properly for your TodoListService project.
97+
1. Open `app.config'.
98+
2. Find the app key `ida:Tenant` and replace the value with your AAD tenant name.
99+
3. Find the app key `ida:ClientId` and replace the value with the Client ID for the TodoListClient from the Azure portal.
100+
4. Find the app key `ida:RedirectUri` and replace the value with the Redirect URI for the TodoListClient from the Azure portal, for example `http://TodoListClient`.
101+
5. Find the app key `todo:TodoListResourceId` and replace the value with the App ID URI of the TodoListService, for example `https://<your_tenant_name>/TodoListService`
102+
6. Find the app key `todo:TodoListBaseAddress` and replace the value with the base address of the TodoListService project.
101103

102104
### Step 5: Trust the IIS Express SSL certificate
103105

@@ -133,11 +135,12 @@ First, in Visual Studio 2013 create an empty solution to host the projects. Th
133135

134136
1. In the solution, create a new Windows --> WPF Application called TodoListClient.
135137
2. Add the (stable) Active Directory Authentication Library (ADAL) NuGet, Microsoft.IdentityModel.Clients.ActiveDirectory, version 1.0.3 (or higher) to the project.
136-
3. Add assembly references to `System.Net.Http` and `System.Web.Extensions`.
138+
3. Add assembly references to `System.Net.Http`, `System.Web.Extensions`, and `System.Configuration`.
137139
4. Add a new class to the project called `TodoItem.cs`. Copy the code from the sample project file of same name into this class, completely replacing the code in the file in the new project.
138140
5. Add a new class to the project called `CacheHelper.cs`. Copy the code from the sample project file of same name into this class, completely replacing the code in the file in the new project.
139141
6. Add a new class to the project called `CredManCache.cs`. Copy the code from the sample project file of same name into this class, completely replacing the code in the file in the new project.
140142
7. Copy the markup from `MainWindow.xaml' in the sample project into the file of same name in the new project, completely replacing the markup in the file in the new project.
141143
8. Copy the code from `MainWindow.xaml.cs` in the sample project into the file of same name in the new project, completely replacing the code in the file in the new project.
144+
9. In `app.config` create keys for `ida:AADInstance`, `ida:Tenant`, `ida:ClientId`, `ida:RedirectUri`, `todo:TodoListResourceId`, and `todo:TodoListBaseAddress` and set them accordingly. For the public Azure cloud, the value of `ida:AADInstance` is `https://login.windows.net/{0}`.
142145

143146
Finally, in the properties of the solution itself, set both projects as startup projects.

TodoListClient/App.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
55
</startup>
6+
<appSettings>
7+
<add key="ida:AADInstance" value="https://login.windows.net/{0}" />
8+
<add key="ida:Tenant" value="skwantoso.com" />
9+
<add key="ida:ClientId" value="fb715b0e-3ca9-45b8-9928-2329a776b42d" />
10+
<add key="ida:RedirectUri" value="http://TodoListClient" />
11+
<add key="todo:TodoListResourceId" value="https://skwantoso.com/TodoListService" />
12+
<add key="todo:TodoListBaseAddress" value="https://localhost:44321" />
13+
</appSettings>
614
</configuration>

TodoListClient/CacheHelper.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
using System;
1+
//----------------------------------------------------------------------------------------------
2+
// Copyright 2014 Microsoft Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//----------------------------------------------------------------------------------------------
16+
17+
using System;
218
using System.Collections.Generic;
319
using System.Linq;
420
using System.Text;
521
using System.Threading.Tasks;
622

23+
// The following using statements were added for this sample.
724
using Microsoft.IdentityModel.Clients.ActiveDirectory;
825

926
namespace TodoListClient

TodoListClient/CredManCache.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
using System;
1+
//----------------------------------------------------------------------------------------------
2+
// Copyright 2014 Microsoft Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//----------------------------------------------------------------------------------------------
16+
17+
using System;
218
using System.Collections.Generic;
319
using System.Linq;
420
using System.Text;
521
using System.Threading.Tasks;
622

23+
// The following using statements were added for this sample.
724
using Microsoft.IdentityModel.Clients.ActiveDirectory;
825
using System.Runtime.InteropServices;
926
using System.Runtime.ConstrainedExecution;

TodoListClient/MainWindow.xaml.cs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
using System;
1+
//----------------------------------------------------------------------------------------------
2+
// Copyright 2014 Microsoft Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//----------------------------------------------------------------------------------------------
16+
17+
using System;
218
using System.Collections.Generic;
319
using System.Linq;
420
using System.Text;
@@ -13,12 +29,14 @@
1329
using System.Windows.Navigation;
1430
using System.Windows.Shapes;
1531

32+
// The following using statements were added for this sample.
1633
using System.Globalization;
1734
using Microsoft.IdentityModel.Clients.ActiveDirectory;
1835
using System.Net.Http;
1936
using System.Net.Http.Headers;
2037
using System.Web.Script.Serialization;
2138
using System.Runtime.InteropServices;
39+
using System.Configuration;
2240

2341
namespace TodoListClient
2442
{
@@ -27,28 +45,26 @@ namespace TodoListClient
2745
/// </summary>
2846
public partial class MainWindow : Window
2947
{
30-
const int INTERNET_OPTION_END_BROWSER_SESSION = 42;
31-
3248
//
3349
// The Client ID is used by the application to uniquely identify itself to Azure AD.
3450
// The Tenant is the name of the Azure AD tenant in which this application is registered.
3551
// The AAD Instance is the instance of Azure, for example public Azure or Azure China.
3652
// The Redirect URI is the URI where Azure AD will return OAuth responses.
3753
// The Authority is the sign-in URL of the tenant.
3854
//
39-
const string aadInstance = "https://login.windows.net/{0}";
40-
const string tenant = "skwantoso.com";
41-
const string clientId = "fb715b0e-3ca9-45b8-9928-2329a776b42d";
42-
Uri redirectUri = new Uri("http://TodoListClient");
55+
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
56+
private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
57+
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
58+
Uri redirectUri = new Uri(ConfigurationManager.AppSettings["ida:RedirectUri"]);
4359

44-
static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
60+
private static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
4561

4662
//
4763
// To authenticate to the To Do list service, the client needs to know the service's App ID URI.
4864
// To contact the To Do list service we need it's URL as well.
4965
//
50-
const string todoListResourceId = "https://skwantoso.com/TodoListService";
51-
const string todoListBaseAddress = "https://localhost:44321";
66+
private static string todoListResourceId = ConfigurationManager.AppSettings["todo:TodoListResourceId"];
67+
private static string todoListBaseAddress = ConfigurationManager.AppSettings["todo:TodoListBaseAddress"];
5268

5369
private HttpClient httpClient = new HttpClient();
5470
private AuthenticationContext authContext = null;
@@ -219,6 +235,8 @@ private void SignIn(object sender = null, RoutedEventArgs args = null)
219235
{
220236
TodoList.ItemsSource = string.Empty;
221237
authContext.TokenCacheStore.Clear();
238+
// Also clear cookies from the browser control.
239+
ClearCookies();
222240
SignInButton.Content = "Sign In";
223241
return;
224242
}
@@ -254,17 +272,12 @@ private void SignIn(object sender = null, RoutedEventArgs args = null)
254272
return;
255273
}
256274

257-
// Uncomment this next line if you want to clear all of the state from the browser control used by ADAL.
258-
// ClearCookies();
259275
}
260276

261-
//
262277
// This function clears cookies from the browser control used by ADAL.
263-
// It is provided here for reference in case you want to reset the cookie state of the browser control.
264-
// It is not used by default in this sample.
265-
//
266278
private void ClearCookies()
267279
{
280+
const int INTERNET_OPTION_END_BROWSER_SESSION = 42;
268281
InternetSetOption(IntPtr.Zero, INTERNET_OPTION_END_BROWSER_SESSION, IntPtr.Zero, 0);
269282
}
270283

TodoListClient/TodoItem.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
using System;
1+
//----------------------------------------------------------------------------------------------
2+
// Copyright 2014 Microsoft Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//----------------------------------------------------------------------------------------------
16+
17+
using System;
218
using System.Collections.Generic;
319
using System.Linq;
420
using System.Text;

TodoListClient/TodoListClient.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<HintPath>..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.1.0.3\lib\net40\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll</HintPath>
4242
</Reference>
4343
<Reference Include="System" />
44+
<Reference Include="System.Configuration" />
4445
<Reference Include="System.Data" />
4546
<Reference Include="System.Net.Http" />
4647
<Reference Include="System.Web.Extensions" />

TodoListService/Controllers/TodoListController.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
using System;
1+
//----------------------------------------------------------------------------------------------
2+
// Copyright 2014 Microsoft Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//----------------------------------------------------------------------------------------------
16+
17+
using System;
218
using System.Collections.Generic;
319
using System.Linq;
420
using System.Net;
521
using System.Net.Http;
622
using System.Web.Http;
723

24+
// The following using statements were added for this sample.
825
using System.Collections.Concurrent;
926
using TodoListService.Models;
1027
using System.Security.Claims;

TodoListService/Models/TodoItem.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
using System;
1+
//----------------------------------------------------------------------------------------------
2+
// Copyright 2014 Microsoft Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//----------------------------------------------------------------------------------------------
16+
17+
using System;
218
using System.Collections.Generic;
319
using System.Linq;
420
using System.Web;

0 commit comments

Comments
 (0)