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

Commit a45e93c

Browse files
committed
Initial working application and README.MD
1 parent 3452052 commit a45e93c

File tree

87 files changed

+28218
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+28218
-0
lines changed

NativeClient-DotNet.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoListService", "TodoListService\TodoListService.csproj", "{047CDEF7-D5BA-4B1E-9748-910B610CCA51}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TodoListClient", "TodoListClient\TodoListClient.csproj", "{005E6BB1-F422-4366-B548-1BDE150F0073}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{047CDEF7-D5BA-4B1E-9748-910B610CCA51}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{005E6BB1-F422-4366-B548-1BDE150F0073}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,142 @@ NativeClient-DotNet
22
===================
33

44
This sample demonstrates a .Net WPF application calling a web API that is secured using Azure AD. The .Net application uses the Active Directory Authentication Library (ADAL) to obtain a JWT access token through the OAuth 2.0 protocol. The access token is sent to the web API to authenticate the user.
5+
6+
For more information about how the protocols work in this scenario and other scenarios, see the [Authentication Scenarios for Azure AD](http://msdn.microsoft.com/aad) document.
7+
8+
## How To Run This Sample
9+
10+
To run this sample you will need:
11+
- Visual Studio 2013
12+
- An Internet connection
13+
- An Azure subscription (a free trial is sufficient)
14+
15+
Every Azure subscription has an associated Azure Active Directory tenant. If you don't already have an Azure subscription, you can get a free subscription by signing up at [http://wwww.windowsazure.com](http://www.windowsazure.com). All of the Azure AD features used by this sample are available free of charge.
16+
17+
### Step 1: Clone or download this repository
18+
19+
From your shell or command line:
20+
21+
`git clone git@github.com:WindowsAzureADSamples/NativeClient-DotNet.git`
22+
23+
### Step 2: Create a user account in your Azure Active Directory tenant
24+
25+
If you already have a user account in your Azure Active Directory tenant, you can skip to the next step. This sample will not work with a Microsoft account, so if you signed in to the Azure portal with a Microsoft account and have never created a user account in your directory before, you need to do that now. If you create an account and want to use it to sign-in to the Azure portal, don't forget to add the user account as a co-administrator of your Azure subscription.
26+
27+
### Step 3: Register the sample with your Azure Active Directory tenant
28+
29+
There are two projects in this sample. Each needs to be separately registered in your Azure AD tenant.
30+
31+
#### Register the TodoListService web API
32+
33+
1. Sign in to the [Azure management portal](https://manage.windowsazure.com).
34+
2. Click on Active Directory in the left hand nav.
35+
3. Click the directory tenant where you wish to register the sample application.
36+
4. Click the Applications tab.
37+
5. In the drawer, click Add.
38+
6. Click "Add an application my organization is developing".
39+
7. Enter a friendly name for the application, for example "TodoListService", select "Web Application and/or Web API", and click next.
40+
8. For the sign-on URL, enter the base URL for the sample, which is by default `https://localhost:44321`.
41+
9. For the App ID URI, enter `https://<your_tenant_name>/TodoListService`, replacing `<your_tenant_name>` with the name of your Azure AD tenant. Click OK to complete the registration.
42+
10. While still in the Azure portal, click the Configure tab of your application.
43+
11. Find the Client ID value and copy it aside, you will need this later when configuring your application.
44+
12. Using the Manage Manifest button in the drawer, download the manifest file for the application.
45+
13. Add a permission to the application by replacing the appPermissions section with the block of JSON below. You will need to create a new GUID and replace the example permissionId GUID.
46+
14. Using the Manage Manfiest button, upload the updated manifest file. Save the configuration of the app.
47+
48+
```JSON
49+
"appPermissions": [
50+
{
51+
"claimValue": "user_impersonation",
52+
"description": "Allow full access to the To Do List service on behalf of the signed-in user",
53+
"directAccessGrantTypes": [],
54+
"displayName": "Have full access to the To Do List service",
55+
"impersonationAccessGrantTypes": [
56+
{
57+
"impersonated": "User",
58+
"impersonator": "Application"
59+
}
60+
],
61+
"isDisabled": false,
62+
"origin": "Application",
63+
"permissionId": "b69ee3c9-c40d-4f2a-ac80-961cd1534e40",
64+
"resourceScopeType": "Personal",
65+
"userConsentDescription": "Allow full access to the To Do service on your behalf",
66+
"userConsentDisplayName": "Have full access to the To Do service"
67+
}
68+
],
69+
```
70+
71+
#### Register the TodoListClient app
72+
73+
1. Sign in to the [Azure management portal](https://manage.windowsazure.com).
74+
2. Click on Active Directory in the left hand nav.
75+
3. Click the directory tenant where you wish to register the sample application.
76+
4. Click the Applications tab.
77+
5. In the drawer, click Add.
78+
6. Click "Add an application my organization is developing".
79+
7. Enter a friendly name for the application, for example "TodoListClient-DotNet", select "Native Client Application", and click next.
80+
8. For the Redirect URI, enter `http://TodoListClient`. Click finish.
81+
9. Click the Configure tab of the application.
82+
10. Find the Client ID value and copy it aside, you will need this later when configuring your application.
83+
11. In "Permissions to Other Applications", select the TodoListService, and request the delegated permission "Have full access to the To Do List service". Save the configuration.
84+
85+
### Step 4: Configure the sample to use your Azure AD tenant
86+
87+
#### Configure the TodoListService project
88+
89+
1. Open the solution in Visual Studio 2013.
90+
2. Open the `web.config` file.
91+
3. Find the app key `ida:Tenant` and replace the value with your AAD tenant name.
92+
4. Find the app key `ida:Audience` and replace the value with the App ID URI you registered earlier, for example `https://<your_tenant_name>/TodoListService`.
93+
5. Find the app key `ida:ClientId` and replace the value with the Client ID for the TodoListService from the Azure portal.
94+
95+
#### Configure the TodoListClient project
96+
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.
101+
102+
### Step 5: Trust the IIS Express SSL certificate
103+
104+
Since the web API is SSL protected, the client of the API (the web app) will refuse the SSL connection to the web API unless it trusts the API's SSL certificate.
105+
106+
Coming soon.
107+
108+
### Step 6: Run the sample
109+
110+
You know what to do! Explore the sample by signing in, adding items to the To Do list, removing the user account, and starting again. Notice that if you stop the application without removing the user account, the next time you run the application you won't be prompted to sign-in again - that is the sample implements a persistent cache for ADAL, and remembers the tokens from the previous run.
111+
112+
## How To Deploy This Sample to Azure
113+
114+
Coming soon.
115+
116+
## About The Code
117+
118+
Coming soon.
119+
120+
## How To Recreate This Sample
121+
122+
First, in Visual Studio 2013 create an empty solution to host the projects. Then, follow these steps to create each project.
123+
124+
### Creating the TodoListService Project
125+
126+
1. In the solution, create a new ASP.Net MVC web API project called TodoListService and while creating the project, click the Change Authentication button, select Organizational Accounts, Cloud - Single Organization, enter the name of your Azure AD tenant, and set the Access Level to Single Sign On. You will be prompted to sign-in to your Azure AD tenant. NOTE: You must sign-in with a user that is in the tenant; you cannot, during this step, sign-in with a Microsoft account.
127+
2. In the `Models` folder add a new class called `TodoItem.cs`. Copy the implementation of TodoItem from this sample into the class.
128+
3. Add a new, empty, Web API 2 controller called `TodoListController`.
129+
4. Copy the implementation of the TodoListController from this sample into the controller. Don't forget to add the `[Authorize]` attribute to the class.
130+
5. In `TodoListController` resolving missing references by adding `using` statements for `System.Collections.Concurrent`, `TodoListService.Models`, `System.Security.Claims`.
131+
132+
### Creating the TodoListClient Project
133+
134+
1. In the solution, create a new Windows --> WPF Application called TodoListClient.
135+
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`.
137+
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.
138+
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.
139+
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.
140+
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.
141+
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.
142+
143+
Finally, in the properties of the solution itself, set both projects as startup projects.

TodoListClient/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

TodoListClient/App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="TodoListClient.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

TodoListClient/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace TodoListClient
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

0 commit comments

Comments
 (0)