Skip to content

Commit 9aab6ee

Browse files
authored
Merge branch 'master' into bogavril/fixcleanup
2 parents 4bbe4a0 + a0bd598 commit 9aab6ee

28 files changed

+198
-148
lines changed

1. Desktop app calls Web API/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ If you want to register your apps manually, as a first step you'll need to:
164164
- Select **Register** to create the application.
165165
1. On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project (`ida:ClientId` in `TodoListClient\App.Config`).
166166
1. From the app's Overview page, select the **Authentication** section.
167-
1. In the **Redirect URIs** list, select for **TYPE** Public client (mobile & desktop). Then paste this value **urn:ietf:wg:oauth:2.0:oob** in the **REDIRECT URI** column.
167+
1. In the **Redirect URIs** list, under **Suggested Redirect URIs for public clients (mobile, desktop)** check the box next to **https://login.microsoftonline.com/common/oauth2/nativeclient**.
168168
1. Select **Save**.
169169
1. Select the **API permissions** section
170170
- Click the **Add a permission** button and then,

1. Desktop app calls Web API/TodoListClient/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public MainWindow()
7575
InitializeComponent();
7676
_app = PublicClientApplicationBuilder.Create(ClientId)
7777
.WithAuthority(Authority)
78+
.WithDefaultRedirectUri()
7879
.Build();
7980

8081
TokenCacheHelper.EnableSerialization(_app.UserTokenCache);

1. Desktop app calls Web API/TodoListClient/TodoListClient.csproj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
<WarningLevel>4</WarningLevel>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="Microsoft.Identity.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
40-
<HintPath>..\packages\Microsoft.Identity.Client.4.0.0\lib\net45\Microsoft.Identity.Client.dll</HintPath>
41-
</Reference>
42-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
44-
</Reference>
4539
<Reference Include="System" />
4640
<Reference Include="System.Configuration" />
4741
<Reference Include="System.Data" />
@@ -102,9 +96,6 @@
10296
<Generator>ResXFileCodeGenerator</Generator>
10397
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
10498
</EmbeddedResource>
105-
<None Include="packages.config">
106-
<SubType>Designer</SubType>
107-
</None>
10899
<None Include="Properties\Settings.settings">
109100
<Generator>SettingsSingleFileGenerator</Generator>
110101
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -116,6 +107,14 @@
116107
<SubType>Designer</SubType>
117108
</None>
118109
</ItemGroup>
110+
<ItemGroup>
111+
<PackageReference Include="Microsoft.Identity.Client">
112+
<Version>4.1.0</Version>
113+
</PackageReference>
114+
<PackageReference Include="Newtonsoft.Json">
115+
<Version>11.0.2</Version>
116+
</PackageReference>
117+
</ItemGroup>
119118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
120119
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
121120
Other similar extension points exist, see Microsoft.Common.targets.

1. Desktop app calls Web API/TodoListClient/packages.config

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

2. Web API now calls Microsoft Graph/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ If you want to register your apps manually, as a first step you'll need to:
186186
- Select **Register** to create the application.
187187
1. On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project (`ida:ClientId` in `TodoListClient\App.Config`).
188188
1. From the app's Overview page, select the **Authentication** section.
189-
1. In the **Redirect URIs** list, select for **TYPE** Public client (mobile & desktop). Then paste this value **urn:ietf:wg:oauth:2.0:oob** in the **REDIRECT URI** column.
189+
1. In the **Redirect URIs** list, under **Suggested Redirect URIs for public clients (mobile, desktop)** check the box next to **https://login.microsoftonline.com/common/oauth2/nativeclient**.
190190
1. Select **Save**.
191191
1. Select the **API permissions** section
192192
- Click the **Add a permission** button and then,

2. Web API now calls Microsoft Graph/TodoListClient/MainWindow.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public MainWindow()
7979
InitializeComponent();
8080
_app = PublicClientApplicationBuilder.Create(ClientId)
8181
.WithAuthority(Authority)
82+
.WithDefaultRedirectUri()
8283
.Build();
8384

8485
TokenCacheHelper.EnableSerialization(_app.UserTokenCache);
@@ -221,7 +222,8 @@ await _app.AcquireTokenInteractive(scopes)
221222
else if (proposedAction == "consent")
222223
{
223224
IPublicClientApplication pca = PublicClientApplicationBuilder.Create(clientId)
224-
.Build();
225+
.WithDefaultRedirectUri()
226+
.Build();
225227
await pca.AcquireTokenInteractive(scopes)
226228
.WithPrompt(Prompt.Consent)
227229
.WithLoginHint(loginHint)

2. Web API now calls Microsoft Graph/TodoListClient/TodoListClient.csproj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
<WarningLevel>4</WarningLevel>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="Microsoft.Identity.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
40-
<HintPath>..\packages\Microsoft.Identity.Client.4.0.0\lib\net45\Microsoft.Identity.Client.dll</HintPath>
41-
</Reference>
42-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
44-
</Reference>
4539
<Reference Include="System" />
4640
<Reference Include="System.Configuration" />
4741
<Reference Include="System.Data" />
@@ -102,9 +96,6 @@
10296
<Generator>ResXFileCodeGenerator</Generator>
10397
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
10498
</EmbeddedResource>
105-
<None Include="packages.config">
106-
<SubType>Designer</SubType>
107-
</None>
10899
<None Include="Properties\Settings.settings">
109100
<Generator>SettingsSingleFileGenerator</Generator>
110101
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -116,6 +107,14 @@
116107
<SubType>Designer</SubType>
117108
</None>
118109
</ItemGroup>
110+
<ItemGroup>
111+
<PackageReference Include="Microsoft.Identity.Client">
112+
<Version>4.1.0</Version>
113+
</PackageReference>
114+
<PackageReference Include="Newtonsoft.Json">
115+
<Version>11.0.2</Version>
116+
</PackageReference>
117+
</ItemGroup>
119118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
120119
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
121120
Other similar extension points exist, see Microsoft.Common.targets.

2. Web API now calls Microsoft Graph/TodoListClient/packages.config

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

3.-Web-api-call-Microsoft-graph-for-personal-accounts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ What **differs from the previous chapter** is that you will use the same applica
172172

173173
1. On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project (`ida:ClientId` in `TodoListClient\App.Config`).
174174
1. From the app's Overview page, select the **Authentication** section.
175-
- In the **Redirect URLs** | Add the following redirect URI: **urn:ietf:wg:oauth:2.0:oob**
175+
- In the **Redirect URIs** list, under **Suggested Redirect URIs for public clients (mobile, desktop)** check the box next to **https://login.microsoftonline.com/common/oauth2/nativeclient**.
176176
- Select **Save**.
177177

178178
### Step 3: Configure the sample to use your Azure AD tenant

3.-Web-api-call-Microsoft-graph-for-personal-accounts/TodoListClient/MainWindow.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public MainWindow()
7979
InitializeComponent();
8080
_app = PublicClientApplicationBuilder.Create(ClientId)
8181
.WithAuthority(Authority)
82+
.WithDefaultRedirectUri()
8283
.Build();
8384

8485
TokenCacheHelper.EnableSerialization(_app.UserTokenCache);
@@ -221,6 +222,7 @@ await _app.AcquireTokenInteractive(scopes)
221222
else if (proposedAction == "consent")
222223
{
223224
IPublicClientApplication pca = PublicClientApplicationBuilder.Create(clientId)
225+
.WithDefaultRedirectUri()
224226
.Build();
225227
await pca.AcquireTokenInteractive(scopes)
226228
.WithPrompt(Prompt.Consent)

3.-Web-api-call-Microsoft-graph-for-personal-accounts/TodoListClient/TodoListClient.csproj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
<WarningLevel>4</WarningLevel>
3737
</PropertyGroup>
3838
<ItemGroup>
39-
<Reference Include="Microsoft.Identity.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
40-
<HintPath>..\packages\Microsoft.Identity.Client.4.0.0\lib\net45\Microsoft.Identity.Client.dll</HintPath>
41-
</Reference>
42-
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43-
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
44-
</Reference>
4539
<Reference Include="System" />
4640
<Reference Include="System.Configuration" />
4741
<Reference Include="System.Data" />
@@ -102,9 +96,6 @@
10296
<Generator>ResXFileCodeGenerator</Generator>
10397
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
10498
</EmbeddedResource>
105-
<None Include="packages.config">
106-
<SubType>Designer</SubType>
107-
</None>
10899
<None Include="Properties\Settings.settings">
109100
<Generator>SettingsSingleFileGenerator</Generator>
110101
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -116,6 +107,14 @@
116107
<SubType>Designer</SubType>
117108
</None>
118109
</ItemGroup>
110+
<ItemGroup>
111+
<PackageReference Include="Microsoft.Identity.Client">
112+
<Version>4.1.0</Version>
113+
</PackageReference>
114+
<PackageReference Include="Newtonsoft.Json">
115+
<Version>11.0.2</Version>
116+
</PackageReference>
117+
</ItemGroup>
119118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
120119
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
121120
Other similar extension points exist, see Microsoft.Common.targets.

3.-Web-api-call-Microsoft-graph-for-personal-accounts/TodoListClient/packages.config

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

Microsoft.Identity.Web.Test/AadIssuerValidatorTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class AadIssuerValidatorTests
1212
{
1313
private const string Tid = "9188040d-6c67-4c5b-b112-36a304b66dad";
1414
private static readonly string Iss = $"https://login.microsoftonline.com/{Tid}/v2.0";
15+
private static readonly string Iss2 = $"https://sts.windows.net/{Tid}/v2.0";
1516
private static readonly IEnumerable<string> s_aliases = new[] { "login.microsoftonline.com", "sts.windows.net" };
1617

1718
[Fact]
@@ -44,6 +45,20 @@ public void PassingValidation()
4445
}
4546

4647

48+
[Fact]
49+
public void PassingValidationWithAlias()
50+
{
51+
// Arrange
52+
AadIssuerValidator validator = new AadIssuerValidator(s_aliases);
53+
Claim issClaim = new Claim("tid", Tid);
54+
Claim tidClaim = new Claim("iss", Iss2); // sts.windows.net
55+
JwtSecurityToken jwtSecurityToken = new JwtSecurityToken(issuer: Iss2, claims: new[] { issClaim, tidClaim });
56+
57+
// Act & Assert
58+
validator.Validate(Iss2, jwtSecurityToken,
59+
new TokenValidationParameters() { ValidIssuers = new[] { "https://login.microsoftonline.com/{tenantid}/v2.0" } });
60+
}
61+
4762
[Fact]
4863
public void TokenValidationParameters_ValidIssuer()
4964
{

Microsoft.Identity.Web/ClaimConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ public static class ClaimConstants
3535
public const string PreferredUserName = "preferred_username";
3636
public const string TenantId = "http://schemas.microsoft.com/identity/claims/tenantid";
3737
public const string Tid = "tid";
38+
public const string Scope = "http://schemas.microsoft.com/identity/claims/scope";
39+
public const string Roles = "roles";
3840
}
3941
}

Microsoft.Identity.Web/ClaimPrincipalExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static string GetLoginHint(this ClaimsPrincipal claimsPrincipal)
8787
/// <summary>
8888
/// Gets the domain-hint associated with an identity
8989
/// </summary>
90-
/// <param name="claimsPrincipal">Identity for which to compte the domain-hint</param>
90+
/// <param name="claimsPrincipal">Identity for which to compute the domain-hint</param>
9191
/// <returns>domain-hint for the identity, or <c>null</c> if it cannot be found</returns>
9292
public static string GetDomainHint(this ClaimsPrincipal claimsPrincipal)
9393
{

Microsoft.Identity.Web/Client/ITokenAcquisition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ITokenAcquisition
1919
/// From the configuration of the Authentication of the ASP.NET Core Web API:
2020
/// <code>OpenIdConnectOptions options;</code>
2121
///
22-
/// Subscribe to the authorization code recieved event:
22+
/// Subscribe to the authorization code received event:
2323
/// <code>
2424
/// options.Events = new OpenIdConnectEvents();
2525
/// options.Events.OnAuthorizationCodeReceived = OnAuthorizationCodeReceived;

Microsoft.Identity.Web/Client/MsalUiRequiredExceptionFilterAttribute.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
31
using Microsoft.AspNetCore.Authentication;
42
using Microsoft.AspNetCore.Http;
53
using Microsoft.AspNetCore.Mvc;
64
using Microsoft.AspNetCore.Mvc.Filters;
75
using Microsoft.Identity.Client;
86
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
7+
using System.Collections.Generic;
8+
using System.Linq;
99

1010
namespace Microsoft.Identity.Web.Client
1111
{
1212
/// <summary>
1313
/// Filter used on a controller action to trigger an incremental consent.
1414
/// </summary>
1515
/// <example>
16-
/// The following controller action will trigger
16+
/// The following controller action will trigger
1717
/// <code>
1818
/// [MsalUiRequiredExceptionFilter(Scopes = new[] {"Mail.Send"})]
1919
/// public async Task<IActionResult> SendEmail()
@@ -24,7 +24,7 @@ namespace Microsoft.Identity.Web.Client
2424
public class MsalUiRequiredExceptionFilterAttribute : ExceptionFilterAttribute
2525
{
2626
public string[] Scopes { get; set; }
27-
27+
2828
public override void OnException(ExceptionContext context)
2929
{
3030
MsalUiRequiredException msalUiRequiredException = context.Exception as MsalUiRequiredException;
@@ -33,7 +33,7 @@ public override void OnException(ExceptionContext context)
3333
msalUiRequiredException = context.Exception?.InnerException as MsalUiRequiredException;
3434
}
3535

36-
if (msalUiRequiredException!=null)
36+
if (msalUiRequiredException != null)
3737
{
3838
if (CanBeSolvedByReSignInUser(msalUiRequiredException))
3939
{
@@ -42,10 +42,10 @@ public override void OnException(ExceptionContext context)
4242
context.Result = new ChallengeResult(properties);
4343
}
4444
}
45-
45+
4646
base.OnException(context);
4747
}
48-
48+
4949
private bool CanBeSolvedByReSignInUser(MsalUiRequiredException ex)
5050
{
5151
// ex.ErrorCode != MsalUiRequiredException.UserNullError indicates a cache problem.
@@ -61,7 +61,7 @@ private bool CanBeSolvedByReSignInUser(MsalUiRequiredException ex)
6161
/// Build Authentication properties needed for an incremental consent.
6262
/// </summary>
6363
/// <param name="scopes">Scopes to request</param>
64-
/// <param name="ex">ui is present</param>
64+
/// <param name="ex">MsalUiRequiredException instance</param>
6565
/// <param name="context">current http context in the pipeline</param>
6666
/// <returns>AuthenticationProperties</returns>
6767
private AuthenticationProperties BuildAuthenticationPropertiesForIncrementalConsent(
@@ -94,4 +94,4 @@ private AuthenticationProperties BuildAuthenticationPropertiesForIncrementalCons
9494
return properties;
9595
}
9696
}
97-
}
97+
}

0 commit comments

Comments
 (0)