Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Commit 890253d

Browse files
committed
Merge branch 'dev'
2 parents 9f18221 + 3660e26 commit 890253d

File tree

656 files changed

+35939
-166471
lines changed

Some content is hidden

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

656 files changed

+35939
-166471
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,6 @@ UpgradeLog*.htm
181181

182182
# Microsoft Fakes
183183
FakesAssemblies/
184+
185+
.vs/
186+
artifacts/

README.md

+14-67
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ This sample shows how to build an MVC web application that uses Azure AD for sig
99

1010
For more information about how the protocols work in this scenario and other scenarios, see [Authentication Scenarios for Azure AD](http://go.microsoft.com/fwlink/?LinkId=394414).
1111

12+
> This sample has finally been updated to ASP.NET Core RC2. Looking for previous versions of this code sample? Check out the tags on the [releases](../../releases) GitHub page.
13+
1214
## How To Run This Sample
1315

14-
To run this sample you will need:
15-
- [Visual Studio 2015](https://www.visualstudio.com/downloads/download-visual-studio-vs)
16+
Getting started is simple! To run this sample you will need:
17+
- [.NET Core & .NET Core SDK RC2 releases](https://www.microsoft.com/net/download)
18+
- [ASP.NET Core RC2 release](https://blogs.msdn.microsoft.com/webdev/2016/05/16/announcing-asp-net-core-rc2/)
19+
- [Visual Studio 2015 Update 2](https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx)
1620
- An Internet connection
1721
- An Azure subscription (a free trial is sufficient)
1822

@@ -22,7 +26,7 @@ Every Azure subscription has an associated Azure Active Directory tenant. If yo
2226

2327
From your shell or command line:
2428

25-
`git clone https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnet5.git`
29+
`git clone https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore.git`
2630

2731
### Step 2: Create a user account in your Azure Active Directory tenant
2832

@@ -41,7 +45,7 @@ There are two projects in this sample. Each needs to be separately registered i
4145
5. In the drawer, click Add.
4246
6. Click "Add an application my organization is developing".
4347
7. Enter a friendly name for the application, for example "TodoListService", select "Web Application and/or Web API", and click next.
44-
8. For the sign-on URL, enter the base URL for the sample, which is by default `https://localhost:44321`.
48+
8. For the sign-on URL, enter the base URL for the sample, which is by default `https://localhost:44351`.
4549
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.
4650
10. While still in the Azure portal, click the Configure tab of your application.
4751
11. Find the Client ID value and copy it aside, you will need this later when configuring your application.
@@ -55,7 +59,7 @@ There are two projects in this sample. Each needs to be separately registered i
5559
5. In the drawer, click Add.
5660
6. Click "Add an application my organization is developing".
5761
7. Enter a friendly name for the application, for example "TodoListWebApp", select "Web Application and/or Web API", and click next.
58-
8. For the sign-on URL, enter the base URL for the sample, which is by default `https://localhost:44322/`. NOTE: It is important, due to the way Azure AD matches URLs, to ensure there is a trailing slash on the end of this URL. If you don't include the trailing slash, you will receive an error when the application attempts to redeem an authorization code.
62+
8. For the sign-on URL, enter the base URL for the sample, which is by default `https://localhost:44371/signin-oidc`.
5963
9. For the App ID URI, enter `https://<your_tenant_name>/TodoListWebApp`, replacing `<your_tenant_name>` with the name of your Azure AD tenant. Click OK to complete the registration.
6064
10. While still in the Azure portal, click the Configure tab of your application.
6165
11. Find the Client ID value and copy it aside, you will need this later when configuring your application.
@@ -67,19 +71,18 @@ There are two projects in this sample. Each needs to be separately registered i
6771
#### Configure the TodoListService project
6872

6973
1. Open the solution in Visual Studio 2015.
70-
2. Open the `config.json` file.
74+
2. Open the `appsettings.json` file.
7175
3. Find the `Tenant` property and replace the value with your AAD tenant name, e.g. contoso.onmicrosoft.com.
72-
4. Find the app key `Audience` and replace the value with the App ID URI you registered earlier, for example `https://<your_tenant_name>/TodoListService`.
76+
4. Find the `Audience` property and replace the value with the App ID URI you registered earlier, for example `https://<your_tenant_name>/TodoListService`.
7377

74-
#### Configure the TodoListWebApp project
78+
#### Configure the WebApp-WebAPI-OpenIDCOnnect-DotNet project
7579

7680
1. Open the solution in Visual Studio 2015.
77-
2. Open the `config.json` file.
81+
2. Open the `appsettings.json` file.
7882
3. Find the `Tenant` property and replace the value with your AAD tenant name, e.g. contoso.onmicrosoft.com.
7983
4. Find the `ClientId` property and replace the value with the Client ID for the TodoListWebApp from the Azure portal.
80-
5. Find the `AppKey` and replace the value with the key for the TodoListWebApp from the Azure portal.
84+
5. Find the `ClientSecret` and replace the value with the key for the TodoListWebApp from the Azure portal.
8185
6. If you changed the base URL of the TodoListWebApp sample, find the `PostLogoutRedirectUri` property and replace the value with the new base URL of the sample.
82-
7. Find the property `TodoListBaseAddress` and make sure it has the correct value for the address of the TodoListService project.
8386
8. Find the `TodoListResourceId` property and replace the value with the App ID URI registered for the TodoListService, for example `https://<your_tenant_name>/TodoListService`.
8487

8588
### Step 5: Trust the IIS Express SSL certificate
@@ -123,59 +126,3 @@ You can verify the certificate is in the Trusted Root store by running this comm
123126
Clean the solution, rebuild the solution, and run it. You might want to go into the solution properties and set both projects as startup projects, with the service project starting first.
124127

125128
Explore the sample by signing in, To Do List link, adding items to the To Do list, signing out, and starting again.
126-
127-
## How To Deploy This Sample to Azure
128-
129-
Coming soon.
130-
131-
## About The Code
132-
133-
Coming soon.
134-
135-
## How To Recreate This Sample
136-
137-
First, in Visual Studio 2015 create an empty solution to host the projects. Then, follow these steps to create each project.
138-
139-
### Creating the TodoListService Project
140-
141-
1. In the solution, create a new "ASP.NET 5 MVC Web API" project called TodoListService.
142-
2. Enable SSL on the project by following the steps outlined in the below section.
143-
2. Add the `Microsoft.AspNet.Security.OAuthBearer` and `Microsoft.Framework.ConfigurationModel.Json` NuGets to the project.
144-
2. Create a new `Models` folder, and add a new class to it called `TodoItem.cs`. Copy the implementation of TodoItem from this sample into the class.
145-
3. Delete the existing `ValuesController.cs`, and add a new Web API controller class called `TodoListController`.
146-
4. Copy the implementation of the TodoListController from this sample into the controller. Don't forget to add the `[Authorize]` attribute to the class.
147-
5. In `TodoListController` resolving missing references by adding `using` statements for `System.Collections.Concurrent`, `TodoListService.Models`, `System.Security.Claims`.
148-
6. Add a new ASP.NET Configuration File called `config.json` to the project. Replace its contents with those of the sample.
149-
7. Replace the implementation of `Startup.cs` with that of the sample, resolving any missing references such as `Microsoft.Framework.ConfigurationModel`.
150-
151-
### Creating the TodoListWebApp Project
152-
153-
1. In Visual Studio 2015 CTP6, create a new "ASP.NET 5 Preview Starter Web" application.
154-
2. Enable SSL for the application by following the steps in section at the bottom of this page.
155-
5. Add the `Microsoft.AspNet.Security.OpenIdConnect` ASP.Net OWIN middleware NuGet to the project. Remember to enable prerelease versions in the NuGet package manager. Also add the prerelease version of `Microsoft.AspNet.Session` to the project.
156-
5. Remove a few excess files that come with the template - they are not needed for this sample. Delete the `Migrations` folder, the `Views/Account` folder, the `Models` folder, and the `Compiler` folder.
157-
6. Replace the implementation of the `Controllers\AccountController.cs` class with the one from the project, resolving any excess or missing using statements.
158-
6. In `Views\Shared`, replace the implementation of `_LoginPartial.cshtml` and `_Layout.cshtml` with the ones from the sample.
159-
7. Replace the contents of `config.json` with the one from the sample.
160-
6. Replace the contents of `Startup.cs` with the one from the sample, resolving any excess or missing using statements. Note that you need to change the class to a `partial` class so you can implement the `ConfigureAuth` method.
161-
7. Create a new folder in the project called `App_Start`, and within it create the `Startup.Auth.cs` class. Again, make sure it's a partial class and copy in the code from the sample. This is where the identity related configuration code occurs.
162-
8. Add a `Models` folder to the project, and create the `TodoItem.cs` class in it. Copy its simple implementation from the sample.
163-
9. Add a `Utils` folder to the project, and create a new class inside it called `NaiveSessionCache.cs`. The `NaiveSessionCache` extends the ADAL token cache, and is used here to store tokens in session storage.
164-
7. Add a new controller to the project, the `TodoListController.cs`. Also create a corresponding `TodoList` view. Copy the implementations in from the sample. Note the use of the `[Authorize]` tag on the `TodoListController` class, to enforce authentication on the methods in this class.
165-
13. Almost done! Follow the steps in "How To Run This Sample" above to register the application in your AAD tenant.
166-
167-
### Enable SSL in Visual Studio 2015 CTP6
168-
These steps are temporarily necessary to enable SSL only for Visual Studio 2015 CTP6: First, hit F5 to run the application. Once you see the homepage, you may close the browser and stop IIS Express. In a text editor, open the file `%userprofile%\documents\IISExpress\config\applicatoinhost.confg`. Find the entry for your app in the `<sites>` node. Add an https protocol binding to this entry for a port between 44300 and 44399, similar to the following:
169-
170-
```
171-
<site name="WebApplication1" id="2">
172-
<application path="/" applicationPool="Clr4IntegratedAppPool">
173-
<virtualDirectory path="/" physicalPath="c:\users\billhie\documents\visual studio 2015\Projects\WebApplication1\WebApplication1" />
174-
</application>
175-
<bindings>
176-
<binding protocol="http" bindingInformation="*:53756:localhost" />
177-
<binding protocol="https" bindingInformation="*:44300:localhost" />
178-
</bindings>
179-
</site>
180-
```
181-
Save and close the file. In Visual Studio, open the properties page of your web app. In the Debug menu, enable the Launch Browser checkbox and enter the same URL as the protocol binding you added, e.g. `https://localhost:44300/`. Your app will now run at this address.

TodoListService/App_Start/Startup.Auth.cs

-18
This file was deleted.

TodoListService/Controllers/HomeController.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using Microsoft.AspNet.Mvc;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
26

37
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
48

@@ -7,7 +11,6 @@ namespace TodoListService.Controllers
711
public class HomeController : Controller
812
{
913
// GET: /<controller>/
10-
[HttpGet("/")]
1114
public IActionResult Index()
1215
{
1316
return View();
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
4-
using Microsoft.AspNet.Mvc;
55
using System.Security.Claims;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Authorization;
8+
using Microsoft.AspNetCore.Mvc;
69
using TodoListService.Models;
7-
using System.Collections.Concurrent;
10+
11+
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
812

913
namespace TodoListService.Controllers
1014
{
@@ -14,22 +18,20 @@ public class TodoListController : Controller
1418
{
1519
static ConcurrentBag<TodoItem> todoStore = new ConcurrentBag<TodoItem>();
1620

17-
// GET: api/todolist
21+
// GET: api/values
1822
[HttpGet]
1923
public IEnumerable<TodoItem> Get()
2024
{
21-
// Please note: use of "Context.User", instead of the standard ClaimsPrincipal.Current, is due to a bug in this release
22-
string owner = Context.User.FindFirst(ClaimTypes.NameIdentifier).Value;
25+
string owner = (User.FindFirst(ClaimTypes.NameIdentifier))?.Value;
2326
return todoStore.Where(t => t.Owner == owner).ToList();
2427
}
25-
26-
// POST api/todolist
28+
29+
// POST api/values
2730
[HttpPost]
28-
public void Post(string Title)
31+
public void Post([FromBody]TodoItem Todo)
2932
{
30-
// Please note: use of "Context.User", instead of the standard ClaimsPrincipal.Current, is due to a bug in this release
31-
string owner = Context.User.FindFirst(ClaimTypes.NameIdentifier).Value;
32-
todoStore.Add(new TodoItem { Owner = owner, Title = Title });
33+
string owner = (User.FindFirst(ClaimTypes.NameIdentifier))?.Value;
34+
todoStore.Add(new TodoItem { Owner = owner, Title = Todo.Title });
3335
}
3436
}
3537
}

TodoListService/Models/TodoItem.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
25

36
namespace TodoListService.Models
47
{
@@ -7,4 +10,4 @@ public class TodoItem
710
public string Owner { get; set; }
811
public string Title { get; set; }
912
}
10-
}
13+
}

TodoListService/Program.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Builder;
8+
9+
namespace TodoListService
10+
{
11+
public class Program
12+
{
13+
// Entry point for the application.
14+
public static void Main(string[] args)
15+
{
16+
var host = new WebHostBuilder()
17+
.UseKestrel()
18+
.UseContentRoot(Directory.GetCurrentDirectory())
19+
.UseIISIntegration()
20+
.UseStartup<Startup>()
21+
.Build();
22+
23+
host.Run();
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)