Skip to content

Commit 2744f7e

Browse files
committed
readd pop stuff and bring over relevant files from MS identity web that are now internal until this moves into MS identity web
1 parent e0da46f commit 2744f7e

File tree

53 files changed

+79
-2447
lines changed

Some content is hidden

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

53 files changed

+79
-2447
lines changed

4.-Console-app-calls-web-API-with-PoP/Desktop-App-calls-Web-API-using-PoP.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
README.md = README.md
1313
EndProjectSection
1414
EndProject
15-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.Future", "..\Microsoft.Identity.Web\Microsoft.Identity.Web.Future.csproj", "{F29C8FF6-5725-4C26-B0B4-682FCF218E6D}"
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.Future", "Microsoft.Identity.Web.Future\Microsoft.Identity.Web.Future.csproj", "{CBA23165-BA0B-469A-B3A4-3299989AAECD}"
1616
EndProject
1717
Global
1818
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -28,10 +28,10 @@ Global
2828
{443FB1A8-4F29-4D18-A4EB-23C3D764580C}.Debug|Any CPU.Build.0 = Debug|Any CPU
2929
{443FB1A8-4F29-4D18-A4EB-23C3D764580C}.Release|Any CPU.ActiveCfg = Release|Any CPU
3030
{443FB1A8-4F29-4D18-A4EB-23C3D764580C}.Release|Any CPU.Build.0 = Release|Any CPU
31-
{F29C8FF6-5725-4C26-B0B4-682FCF218E6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32-
{F29C8FF6-5725-4C26-B0B4-682FCF218E6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
33-
{F29C8FF6-5725-4C26-B0B4-682FCF218E6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
34-
{F29C8FF6-5725-4C26-B0B4-682FCF218E6D}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{CBA23165-BA0B-469A-B3A4-3299989AAECD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{CBA23165-BA0B-469A-B3A4-3299989AAECD}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{CBA23165-BA0B-469A-B3A4-3299989AAECD}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{CBA23165-BA0B-469A-B3A4-3299989AAECD}.Release|Any CPU.Build.0 = Release|Any CPU
3535
EndGlobalSection
3636
GlobalSection(SolutionProperties) = preSolution
3737
HideSolutionNode = FALSE

Microsoft.Identity.Web/Resource/AadIssuerValidator.cs renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/AadIssuerValidator.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
using Microsoft.IdentityModel.JsonWebTokens;
1010
using Microsoft.IdentityModel.Protocols;
1111
using Microsoft.IdentityModel.Tokens;
12-
using Microsoft.Identity.Web.InstanceDiscovery;
12+
using Microsoft.Identity.Web.Future;
1313

14-
namespace Microsoft.Identity.Web.Resource
14+
namespace Microsoft.Identity.Future
1515
{
1616
/// <summary>
1717
/// Generic class that validates token issuer from the provided Azure AD authority. Use the <see cref="AadIssuerValidatorFactory"/> to create instances of this class.
1818
/// </summary>
19-
public class AadIssuerValidator
19+
internal class AadIssuerValidator
2020
{
2121
private const string AzureADIssuerMetadataUrl = "https://login.microsoftonline.com/common/discovery/instance?authorization_endpoint=https://login.microsoftonline.com/common/oauth2/v2.0/authorize&api-version=1.1";
2222
private const string FallbackAuthority = "https://login.microsoftonline.com/";
@@ -71,6 +71,7 @@ public static AadIssuerValidator GetIssuerValidator(string aadAuthority)
7171
var aliases = issuerMetadata.Metadata
7272
.Where(m => m.Aliases.Any(a => string.Equals(a, authority, StringComparison.OrdinalIgnoreCase)))
7373
.SelectMany(m => m.Aliases)
74+
.Append(authority) // For b2c scenarios, the alias will be the authorityHost itself
7475
.Distinct();
7576
s_issuerValidators[authority] = new AadIssuerValidator(aliases);
7677
return s_issuerValidators[authority];
@@ -94,7 +95,7 @@ public static AadIssuerValidator GetIssuerValidator(string aadAuthority)
9495
/// <exception cref="SecurityTokenInvalidIssuerException">if the issuer </exception>
9596
public string Validate(string actualIssuer, SecurityToken securityToken, TokenValidationParameters validationParameters)
9697
{
97-
if (String.IsNullOrEmpty(actualIssuer))
98+
if (string.IsNullOrEmpty(actualIssuer))
9899
throw new ArgumentNullException(nameof(actualIssuer));
99100

100101
if (securityToken == null)
@@ -159,21 +160,43 @@ private static bool IsValidTidInLocalPath(string tenantId, Uri uri)
159160
/// <remarks>Only <see cref="JwtSecurityToken"/> and <see cref="JsonWebToken"/> are acceptable types.</remarks>
160161
private static string GetTenantIdFromToken(SecurityToken securityToken)
161162
{
163+
string tid = "tid";
162164
if (securityToken is JwtSecurityToken jwtSecurityToken)
163165
{
164-
if (jwtSecurityToken.Payload.TryGetValue(ClaimConstants.Tid, out object tenantId))
166+
if (jwtSecurityToken.Payload.TryGetValue(tid, out object tenantId))
165167
return tenantId as string;
168+
169+
// Since B2C doesn't have TID as default, get it from issuer
170+
return GetTenantIdFromIss(jwtSecurityToken.Issuer);
166171
}
167172

168-
// brentsch - todo, TryGetPayloadValue is available in 5.5.0
169173
if (securityToken is JsonWebToken jsonWebToken)
170174
{
171-
var tid = jsonWebToken.GetPayloadValue<string>(ClaimConstants.Tid);
172-
if (tid != null)
173-
return tid;
175+
jsonWebToken.TryGetPayloadValue(tid, out string tid2);
176+
if (tid2 != null)
177+
return tid2;
178+
179+
// Since B2C doesn't have TID as default, get it from issuer
180+
return GetTenantIdFromIss(jsonWebToken.Issuer);
181+
}
182+
183+
return string.Empty;
184+
}
185+
186+
// The AAD iss claims contains the tenantId in its value. The uri is {domain}/{tid}/v2.0
187+
private static string GetTenantIdFromIss(string iss)
188+
{
189+
if (string.IsNullOrEmpty(iss))
190+
return string.Empty;
191+
192+
var uri = new Uri(iss);
193+
194+
if (uri.Segments.Length > 1)
195+
{
196+
return uri.Segments[1].TrimEnd('/');
174197
}
175198

176199
return string.Empty;
177200
}
178201
}
179-
}
202+
}

Microsoft.Identity.Web/InstanceDiscovery/IssuerConfigurationRetriever.cs renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/IssuerConfigurationRetriever.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Microsoft.IdentityModel.Protocols;
88
using Newtonsoft.Json;
99

10-
namespace Microsoft.Identity.Web.InstanceDiscovery
10+
namespace Microsoft.Identity.Web.Future
1111
{
1212
/// <summary>
1313
/// An implementation of IConfigurationRetriever geared towards Azure AD issuers metadata />

Microsoft.Identity.Web/InstanceDiscovery/IssuerMetadata.cs renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/IssuerMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using Newtonsoft.Json;
66

7-
namespace Microsoft.Identity.Web.InstanceDiscovery
7+
namespace Microsoft.Identity.Web.Future
88
{
99
/// <summary>
1010
/// Model class to hold information parsed from the Azure AD issuer endpoint

Microsoft.Identity.Web/InstanceDiscovery/Metadata.cs renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/Metadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections.Generic;
55
using Newtonsoft.Json;
66

7-
namespace Microsoft.Identity.Web.InstanceDiscovery
7+
namespace Microsoft.Identity.Web.Future
88
{
99
/// <summary>
1010
/// Model child class to hold alias information parsed from the Azure AD issuer endpoint.

Microsoft.Identity.Web/Microsoft.Identity.Web.Future.csproj renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/Microsoft.Identity.Web.Future.csproj

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33

44
<!--This should be passed from the VSTS build-->
5-
<ClientSemVer Condition="'$(ClientSemVer)' == ''">1.0.0-localbuild</ClientSemVer>
5+
<ClientSemVer Condition="'$(ClientSemVer)' == ''">1.0.0-preview</ClientSemVer>
66
<!--This will generate AssemblyVersion, AssemblyFileVersion and AssemblyInformationVersion-->
77
<Version>$(ClientSemVer)</Version>
88

@@ -26,34 +26,6 @@
2626
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2727
</PropertyGroup>
2828

29-
<ItemGroup>
30-
<Compile Remove="InstanceDiscovery\**" />
31-
<Compile Remove="Resource\**" />
32-
<Compile Remove="TokenCacheProviders\**" />
33-
<EmbeddedResource Remove="InstanceDiscovery\**" />
34-
<EmbeddedResource Remove="Resource\**" />
35-
<EmbeddedResource Remove="TokenCacheProviders\**" />
36-
<None Remove="InstanceDiscovery\**" />
37-
<None Remove="Resource\**" />
38-
<None Remove="TokenCacheProviders\**" />
39-
</ItemGroup>
40-
41-
<ItemGroup>
42-
<Compile Remove="AccountExtensions.cs" />
43-
<Compile Remove="AuthorizeForScopesAttribute.cs" />
44-
<Compile Remove="ClaimConstants.cs" />
45-
<Compile Remove="ClaimsPrincipalExtensions.cs" />
46-
<Compile Remove="ClaimsPrincipalFactory.cs" />
47-
<Compile Remove="Extensions.cs" />
48-
<Compile Remove="HttpContextExtensions.cs" />
49-
<Compile Remove="InternalsVisibleTo.cs" />
50-
<Compile Remove="ITokenAcquisition.cs" />
51-
<Compile Remove="OidcConstants.cs" />
52-
<Compile Remove="ServiceCollectionExtensions.cs" />
53-
<Compile Remove="TokenAcquisition.cs" />
54-
<Compile Remove="WebAppServiceCollectionExtensions.cs" />
55-
</ItemGroup>
56-
5729
<ItemGroup>
5830
<None Remove="NuGet.Config" />
5931
<None Remove="README.md" />
@@ -79,10 +51,6 @@
7951
</PropertyGroup>
8052

8153
<ItemGroup>
82-
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="3.1.0" />
83-
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureADB2C.UI" Version="3.1.0" />
84-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.3" />
85-
<PackageReference Include="Microsoft.Identity.Client" Version="4.11.0" />
8654
<PackageReference Include="Microsoft.Identity.Web" Version="0.1.0-preview" />
8755
<PackageReference Include="Microsoft.IdentityModel.Protocols.SignedHttpRequest" Version="6.5.0" />
8856
<PackageReference Include="System.Collections" Version="4.3.0" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29911.84
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Identity.Web.Future", "Microsoft.Identity.Web.Future.csproj", "{11CCC8C7-5E85-457D-ADD4-AA03E40A9AAC}"
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+
{11CCC8C7-5E85-457D-ADD4-AA03E40A9AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{11CCC8C7-5E85-457D-ADD4-AA03E40A9AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{11CCC8C7-5E85-457D-ADD4-AA03E40A9AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{11CCC8C7-5E85-457D-ADD4-AA03E40A9AAC}.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 = {E7B6C459-1C2D-49FB-9B76-E94D243D586A}
24+
EndGlobalSection
25+
EndGlobal

Microsoft.Identity.Web/Microsoft.Identity.Web.ruleset renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/Microsoft.Identity.Web.ruleset

File renamed without changes.

Microsoft.Identity.Web/Microsoft.Identity.Web.sln renamed to 4.-Console-app-calls-web-API-with-PoP/Microsoft.Identity.Web.Future/Microsoft.Identity.Web.sln

File renamed without changes.
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+
<packageSources>
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
5+
</packageSources>
6+
</configuration>

0 commit comments

Comments
 (0)