Skip to content

Commit 33368eb

Browse files
committed
Merge Master
2 parents 0347730 + c834e5c commit 33368eb

File tree

252 files changed

+120482
-72976
lines changed

Some content is hidden

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

252 files changed

+120482
-72976
lines changed

1-WebApp-OIDC/1-1-MyOrg/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ As a first step you'll need to:
9898
- `https://localhost:44321/signin-oidc`
9999
- In the **Advanced settings** section set **Logout URL** to `https://localhost:44321/signout-oidc`
100100
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires
101-
the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to
101+
the [ID Token](https://docs.microsoft.com/azure/active-directory/develop/id-tokens) to be enabled to
102102
sign-in the user.
103103
<details open=true>
104104
<summary>Expand/collapse screenshot</summary>
@@ -221,7 +221,7 @@ You can trigger the middleware to send an OpenID Connect sign-in request by deco
221221
222222
The middleware in this project is created as a part of the open-source [ASP.NET Core Security](https://github.com/aspnet/aspnetcore) project.
223223
224-
These steps are encapsulated in the [Microsoft.Identity.Web](..\..\Microsoft.Identity.Web) project, and in particular in the [StartupHelper.cs](..\..\Microsoft.Identity.Web\StartupHelper.cs) file
224+
These steps are encapsulated in the [Microsoft.Identity.Web](https://github.com/AzureAD/microsoft-identity-web/wiki) library.
225225
226226
## Next steps
227227
Learn how to:

1-WebApp-OIDC/1-1-MyOrg/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2626
</PackageReference>
2727
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
28-
<PackageReference Include="Microsoft.Identity.Web" Version="0.3.0-preview" />
29-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.3.0-preview" />
28+
<PackageReference Include="Microsoft.Identity.Web" Version="0.4.0-preview" />
29+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.4.0-preview" />
3030
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
3131
</ItemGroup>
3232

1-WebApp-OIDC/1-2-AnyOrg/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ You can trigger the middleware to send an OpenID Connect sign-in request by deco
215215
216216
The middleware in this project is created as a part of the open-source [ASP.NET Core Security](https://github.com/aspnet/aspnetcore) project.
217217
218-
These steps are encapsulated in the [Microsoft.Identity.Web](..\..\Microsoft.Identity.Web) project, and in particular in the [StartupHelper.cs](..\..\Microsoft.Identity.Web\StartupHelper.cs) file
218+
These steps are encapsulated in the [Microsoft.Identity.Web](https://github.com/AzureAD/microsoft-identity-web/wiki) library.
219219
220220
## How to restrict users from specific organizations from signing-in your web app
221221

1-WebApp-OIDC/1-2-AnyOrg/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="0.3.0-preview" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.3.0-preview" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="0.4.0-preview" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.4.0-preview" />
2323
</ItemGroup>
2424

2525
</Project>

1-WebApp-OIDC/1-3-AnyOrgOrPersonal/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ As a first step you'll need to:
9393
- `https://localhost:44321/signin-oidc`
9494
- In the **Advanced settings** section set **Logout URL** to `https://localhost:44321/signout-oidc`
9595
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires
96-
the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to
96+
the [ID Token](https://docs.microsoft.com/azure/active-directory/develop/id-tokens) to be enabled to
9797
sign-in the user.
9898
1. Select **Save**.
9999

1-WebApp-OIDC/1-3-AnyOrgOrPersonal/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="0.3.0-preview" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.3.0-preview" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="0.4.0-preview" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.4.0-preview" />
2323
</ItemGroup>
2424

2525
</Project>

1-WebApp-OIDC/1-4-Sovereign/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cd "1-WebApp-OIDC\1-4-Sovereign"
7777
1. In the list of pages for the app, select **Authentication**.
7878
- In the **Redirect URIs**, add a redirect URL of type Web and valued `https://localhost:44321/signin-oidc`
7979
- In the **Advanced settings** section set **Logout URL** to `https://localhost:44321/signout-oidc`
80-
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires the [Implicit grant flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to be enabled to sign in the user.
80+
- In the **Advanced settings** | **Implicit grant** section, check **ID tokens** as this sample requires the [ID Token](https://docs.microsoft.com/azure/active-directory/develop/id-tokens) to be enabled to sign in the user.
8181
- Select **Save**.
8282

8383
> Note that unless the Web App calls a Web API no certificate or secret is needed.

1-WebApp-OIDC/1-4-Sovereign/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="0.3.0-preview" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.3.0-preview" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="0.4.0-preview" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.4.0-preview" />
2323
</ItemGroup>
2424

2525
</Project>

1-WebApp-OIDC/1-5-B2C/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Identity.Web" Version="0.3.0-preview" />
22-
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.3.0-preview" />
21+
<PackageReference Include="Microsoft.Identity.Web" Version="0.4.0-preview" />
22+
<PackageReference Include="Microsoft.Identity.Web.UI" Version="0.4.0-preview" />
2323
</ItemGroup>
2424

2525
</Project>
Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29123.89
5-
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp-OpenIDConnect-DotNet", "WebApp-OpenIDConnect-DotNet.csproj", "{8DCFEEC2-0A85-4C7E-B96A-21C9184470B1}"
7-
EndProject
8-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CD0BB564-6C1E-4FCE-B9AB-7C637FDEE569}"
9-
ProjectSection(SolutionItems) = preProject
10-
.editorconfig = .editorconfig
11-
EndProjectSection
12-
EndProject
13-
Global
14-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
15-
Debug|Any CPU = Debug|Any CPU
16-
Release|Any CPU = Release|Any CPU
17-
EndGlobalSection
18-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19-
{8DCFEEC2-0A85-4C7E-B96A-21C9184470B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{8DCFEEC2-0A85-4C7E-B96A-21C9184470B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
21-
{8DCFEEC2-0A85-4C7E-B96A-21C9184470B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
22-
{8DCFEEC2-0A85-4C7E-B96A-21C9184470B1}.Release|Any CPU.Build.0 = Release|Any CPU
23-
EndGlobalSection
24-
GlobalSection(SolutionProperties) = preSolution
25-
HideSolutionNode = FALSE
26-
EndGlobalSection
27-
GlobalSection(ExtensibilityGlobals) = postSolution
28-
SolutionGuid = {4FC144FA-5678-428C-B5B7-E2A88ADE849D}
29-
EndGlobalSection
30-
EndGlobal
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30413.136
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp-OpenIDConnect-DotNet", "WebApp-OpenIDConnect-DotNet.csproj", "{76F9C1E5-3CF7-4C9A-A0EC-D15B5F11022D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{76F9C1E5-3CF7-4C9A-A0EC-D15B5F11022D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{76F9C1E5-3CF7-4C9A-A0EC-D15B5F11022D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{76F9C1E5-3CF7-4C9A-A0EC-D15B5F11022D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{76F9C1E5-3CF7-4C9A-A0EC-D15B5F11022D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {AB49E34F-5B62-4F54-BAEA-C6473483C761}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 71 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,71 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.IO;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Authorization;
6-
using Microsoft.AspNetCore.Mvc;
7-
using Microsoft.Extensions.Options;
8-
using Graph=Microsoft.Graph;
9-
using Microsoft.Identity.Web;
10-
using WebApp_OpenIDConnect_DotNet.Infrastructure;
11-
using WebApp_OpenIDConnect_DotNet.Models;
12-
using WebApp_OpenIDConnect_DotNet.Services;
13-
14-
namespace WebApp_OpenIDConnect_DotNet.Controllers
15-
{
16-
[Authorize]
17-
public class HomeController : Controller
18-
{
19-
readonly ITokenAcquisition tokenAcquisition;
20-
readonly WebOptions webOptions;
21-
22-
public HomeController(ITokenAcquisition tokenAcquisition,
23-
IOptions<WebOptions> webOptionValue)
24-
{
25-
this.tokenAcquisition = tokenAcquisition;
26-
this.webOptions = webOptionValue.Value;
27-
}
28-
29-
public IActionResult Index()
30-
{
31-
return View();
32-
}
33-
34-
[AuthorizeForScopes(Scopes = new[] { Constants.ScopeUserRead })]
35-
public async Task<IActionResult> Profile()
36-
{
37-
// Initialize the GraphServiceClient.
38-
Graph::GraphServiceClient graphClient = GetGraphServiceClient(new[] { Constants.ScopeUserRead });
39-
40-
var me = await graphClient.Me.Request().GetAsync();
41-
ViewData["Me"] = me;
42-
43-
try
44-
{
45-
// Get user photo
46-
using (var photoStream = await graphClient.Me.Photo.Content.Request().GetAsync())
47-
{
48-
byte[] photoByte = ((MemoryStream)photoStream).ToArray();
49-
ViewData["Photo"] = Convert.ToBase64String(photoByte);
50-
}
51-
}
52-
catch (System.Exception)
53-
{
54-
ViewData["Photo"] = null;
55-
}
56-
57-
return View();
58-
}
59-
60-
private Graph::GraphServiceClient GetGraphServiceClient(string[] scopes)
61-
{
62-
return GraphServiceClientFactory.GetAuthenticatedGraphClient(async () =>
63-
{
64-
string result = await tokenAcquisition.GetAccessTokenForUserAsync(scopes);
65-
return result;
66-
}, webOptions.GraphApiUrl);
67-
}
68-
69-
[AllowAnonymous]
70-
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
71-
public IActionResult Error()
72-
{
73-
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
74-
}
75-
}
76-
}
1+
using System;
2+
using System.Diagnostics;
3+
using System.Threading.Tasks;
4+
using Microsoft.AspNetCore.Authorization;
5+
using Microsoft.Identity.Web;
6+
using Microsoft.Graph;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.Extensions.Logging;
9+
using _2_1_Call_MSGraph.Models;
10+
using System.IO;
11+
12+
namespace _2_1_Call_MSGraph.Controllers
13+
{
14+
[Authorize]
15+
public class HomeController : Controller
16+
{
17+
private readonly ILogger<HomeController> _logger;
18+
19+
private readonly GraphServiceClient _graphServiceClient;
20+
21+
public HomeController(ILogger<HomeController> logger,
22+
GraphServiceClient graphServiceClient)
23+
{
24+
_logger = logger;
25+
_graphServiceClient = graphServiceClient;
26+
}
27+
28+
[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
29+
public async Task<IActionResult> Index()
30+
{
31+
var user = await _graphServiceClient.Me.Request().GetAsync();
32+
ViewData["ApiResult"] = user.DisplayName;
33+
34+
return View();
35+
}
36+
37+
[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
38+
public async Task<IActionResult> Profile()
39+
{
40+
var me = await _graphServiceClient.Me.Request().GetAsync();
41+
ViewData["Me"] = me;
42+
43+
try
44+
{
45+
// Get user photo
46+
using (var photoStream = await _graphServiceClient.Me.Photo.Content.Request().GetAsync())
47+
{
48+
byte[] photoByte = ((MemoryStream)photoStream).ToArray();
49+
ViewData["Photo"] = Convert.ToBase64String(photoByte);
50+
}
51+
}
52+
catch (System.Exception)
53+
{
54+
ViewData["Photo"] = null;
55+
}
56+
57+
return View();
58+
}
59+
public IActionResult Privacy()
60+
{
61+
return View();
62+
}
63+
64+
[AllowAnonymous]
65+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
66+
public IActionResult Error()
67+
{
68+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
69+
}
70+
}
71+
}

2-WebApp-graph-user/2-1-Call-MSGraph/Infrastructure/Constants.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace WebApp_OpenIDConnect_DotNet.Models
2-
{
3-
public class ErrorViewModel
4-
{
5-
public string RequestId { get; set; }
6-
7-
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8-
}
9-
}
1+
namespace _2_1_Call_MSGraph.Models
2+
{
3+
public class ErrorViewModel
4+
{
5+
public string RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
9+
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using Microsoft.Extensions.Hosting;
2-
using Microsoft.AspNetCore.Hosting;
3-
4-
namespace WebApp_OpenIDConnect_DotNet
5-
{
6-
public class Program
7-
{
8-
public static void Main(string[] args)
9-
{
10-
CreateHostBuilder(args).Build().Run();
11-
}
12-
13-
public static IHostBuilder CreateHostBuilder(string[] args) =>
14-
Host.CreateDefaultBuilder(args)
15-
.ConfigureWebHostDefaults(webBuilder =>
16-
{
17-
webBuilder.UseStartup<Startup>();
18-
});
19-
}
20-
}
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace _2_1_Call_MSGraph
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}

0 commit comments

Comments
 (0)