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

Commit 5fef217

Browse files
authored
Merge pull request #24 from Azure-Samples/aspnet20
Updating the sample to ASP.NET Core 2.0
2 parents 9fe1ca0 + 94de6d7 commit 5fef217

File tree

454 files changed

+30170
-20787
lines changed

Some content is hidden

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

454 files changed

+30170
-20787
lines changed

README.md

Lines changed: 115 additions & 76 deletions
Large diffs are not rendered by default.

Readme/todolist-webApp.png

57.1 KB
Loading

TodoListService/Controllers/HomeController.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

TodoListService/Controllers/TodoListController.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
using System;
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
23
using System.Collections.Concurrent;
34
using System.Collections.Generic;
45
using System.Linq;
56
using System.Security.Claims;
6-
using System.Threading.Tasks;
7-
using Microsoft.AspNetCore.Authorization;
8-
using Microsoft.AspNetCore.Mvc;
97
using TodoListService.Models;
108

11-
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
12-
139
namespace TodoListService.Controllers
1410
{
15-
[Authorize]
11+
[Authorize]
1612
[Route("api/[controller]")]
1713
public class TodoListController : Controller
1814
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using Microsoft.AspNetCore.Authentication.JwtBearer;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Options;
6+
7+
namespace Microsoft.AspNetCore.Authentication
8+
{
9+
public static class AzureAdServiceCollectionExtensions
10+
{
11+
public static AuthenticationBuilder AddAzureAdBearer(this AuthenticationBuilder builder)
12+
=> builder.AddAzureAdBearer(_ => { });
13+
14+
public static AuthenticationBuilder AddAzureAdBearer(this AuthenticationBuilder builder, Action<AzureAdOptions> configureOptions)
15+
{
16+
builder.Services.Configure(configureOptions);
17+
builder.Services.AddSingleton<IConfigureOptions<JwtBearerOptions>, ConfigureAzureOptions>();
18+
builder.AddJwtBearer();
19+
return builder;
20+
}
21+
22+
private class ConfigureAzureOptions: IConfigureNamedOptions<JwtBearerOptions>
23+
{
24+
private readonly AzureAdOptions _azureOptions;
25+
26+
public ConfigureAzureOptions(IOptions<AzureAdOptions> azureOptions)
27+
{
28+
_azureOptions = azureOptions.Value;
29+
}
30+
31+
public void Configure(string name, JwtBearerOptions options)
32+
{
33+
options.Audience = _azureOptions.ClientId;
34+
options.Authority = $"{_azureOptions.Instance}{_azureOptions.TenantId}";
35+
}
36+
37+
public void Configure(JwtBearerOptions options)
38+
{
39+
Configure(Options.DefaultName, options);
40+
}
41+
}
42+
}
43+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Microsoft.AspNetCore.Authentication
2+
{
3+
public class AzureAdOptions
4+
{
5+
public string ClientId { get; set; }
6+
public string ClientSecret { get; set; }
7+
public string Instance { get; set; }
8+
public string Domain { get; set; }
9+
public string TenantId { get; set; }
10+
}
11+
}

TodoListService/Models/TodoItem.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
6-
namespace TodoListService.Models
1+
namespace TodoListService.Models
72
{
83
public class TodoItem
94
{

TodoListService/Program.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
67
using Microsoft.AspNetCore.Hosting;
7-
using Microsoft.AspNetCore.Builder;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
810

911
namespace TodoListService
1012
{
1113
public class Program
1214
{
13-
// Entry point for the application.
1415
public static void Main(string[] args)
1516
{
16-
var host = new WebHostBuilder()
17-
.UseKestrel()
18-
.UseContentRoot(Directory.GetCurrentDirectory())
19-
.UseIISIntegration()
17+
BuildWebHost(args).Run();
18+
}
19+
20+
public static IWebHost BuildWebHost(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
2022
.UseStartup<Startup>()
2123
.Build();
22-
23-
host.Run();
24-
}
2524
}
2625
}

TodoListService/Project_Readme.html

Lines changed: 0 additions & 187 deletions
This file was deleted.

TodoListService/Properties/launchSettings.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "https://localhost:44351/",
7-
"sslPort": 44351
6+
"applicationUrl": "https://localhost:44351",
7+
"sslPort": 44398
88
}
99
},
1010
"profiles": {
1111
"IIS Express": {
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
14+
"launchUrl": "https://localhost:44351/api/todolist",
1415
"environmentVariables": {
1516
"ASPNETCORE_ENVIRONMENT": "Development"
1617
}
18+
},
19+
"TodoListService": {
20+
"commandName": "Project",
21+
"launchBrowser": true,
22+
"environmentVariables": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"applicationUrl": "http://localhost:1040/"
1726
}
1827
}
1928
}

0 commit comments

Comments
 (0)