Skip to content

Commit b008537

Browse files
Adding AT PoP skeleton (#2511)
* adding "-AT PoP" option to "Set-MgGraphOptions" ---------
1 parent 061614d commit b008537

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

docs/authentication.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Before using the provided `-AccessToken` to get Microsoft Graph resources, custo
116116

117117
AT PoP is a security mechanism that binds an access token to a cryptographic key that only the intended recipient has. This prevents unauthorized use of the token by malicious actors. AT PoP enhances data protection, reduces token replay attacks, and enables fine-grained authorization policies.
118118

119+
Note: AT PoP requires WAM to function.
120+
119121
Microsoft Graph PowerShell module supports AT PoP in the following scenario:
120122

121123
- To enable AT PoP on supported devices

src/Authentication/Authentication.Core/Microsoft.Graph.Authentication.Core.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<Import Project="$(MSBuildThisFileDirectory)..\..\..\Repo.props" />
33
<PropertyGroup>
44
<LangVersion>9.0</LangVersion>
55
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
66
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
7-
<Version>2.18.0</Version>
7+
<Version>2.12.0</Version>
88
</PropertyGroup>
99
<PropertyGroup>
1010
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1111
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Azure.Identity" Version="1.11.0" />
15-
<PackageReference Include="Azure.Identity.Broker" Version="1.0.0-beta.5" />
16-
<PackageReference Include="Azure.Identity.BrokeredAuthentication" Version="1.0.0-beta.3" />
17-
<PackageReference Include="Microsoft.Graph.Core" Version="3.0.9" />
18-
<PackageReference Include="Microsoft.Identity.Client" Version="4.56.0" />
19-
<PackageReference Include="Microsoft.Identity.Client.Broker" Version="4.56.0" />
14+
<PackageReference Include="Azure.Identity" Version="1.11.0-beta.1" />
15+
<PackageReference Include="Azure.Core" Version="1.38.0" />
16+
<PackageReference Include="Azure.Identity.Broker" Version="1.1.0-beta.1" />
17+
<PackageReference Include="Microsoft.Graph.Core" Version="3.1.8" />
18+
<PackageReference Include="Microsoft.Identity.Client" Version="4.59.0" />
19+
<PackageReference Include="Microsoft.Identity.Client.Broker" Version="4.59.0" />
2020
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2121
</ItemGroup>
2222
<Target Name="CopyFiles" AfterTargets="Build">

src/Authentication/Authentication.Core/Utilities/AuthenticationHelpers.cs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// ------------------------------------------------------------------------------
44
using Azure.Core;
55
using Azure.Core.Diagnostics;
6+
using Azure.Core.Pipeline;
67
using Azure.Identity;
78
using Azure.Identity.Broker;
89
using Microsoft.Graph.Authentication;
@@ -86,6 +87,12 @@ private static bool IsWamSupported()
8687
return GraphSession.Instance.GraphOption.EnableWAMForMSGraph && SharedUtilities.IsWindowsPlatform();
8788
}
8889

90+
//Check to see if ATPoP is Supported
91+
private static bool IsATPoPSupported()
92+
{
93+
return GraphSession.Instance.GraphOption.EnableATPoPForMSGraph;
94+
}
95+
8996
private static async Task<TokenCredential> GetClientSecretCredentialAsync(IAuthContext authContext)
9097
{
9198
if (authContext is null)
@@ -125,11 +132,45 @@ private static async Task<InteractiveBrowserCredential> GetInteractiveBrowserCre
125132
var interactiveBrowserCredential = new InteractiveBrowserCredential(interactiveOptions);
126133
if (IsWamSupported())
127134
{
128-
authRecord = await Task.Run(() =>
135+
// Adding a scenario to account for Access Token Proof of Possession
136+
if (IsATPoPSupported())
129137
{
130-
// Run the thread in MTA.
131-
return interactiveBrowserCredential.Authenticate(new TokenRequestContext(authContext.Scopes), cancellationToken);
132-
});
138+
// Logic to implement ATPoP Authentication
139+
authRecord = await Task.Run(() =>
140+
{
141+
var popTokenAuthenticationPolicy = new PopTokenAuthenticationPolicy(interactiveBrowserCredential as ISupportsProofOfPossession, $"https://graph.microsoft.com/.default");
142+
143+
var pipelineOptions = new HttpPipelineOptions(new PopClientOptions()
144+
{
145+
Diagnostics =
146+
{
147+
IsLoggingContentEnabled = true,
148+
LoggedHeaderNames = { "Authorization" }
149+
},
150+
});
151+
pipelineOptions.PerRetryPolicies.Add(popTokenAuthenticationPolicy);
152+
153+
var _pipeline = HttpPipelineBuilder.Build(pipelineOptions, new HttpPipelineTransportOptions { ServerCertificateCustomValidationCallback = (_) => true });
154+
using var request = _pipeline.CreateRequest();
155+
request.Method = RequestMethod.Get;
156+
request.Uri.Reset(new Uri("https://20.190.132.47/beta/me"));
157+
var response = _pipeline.SendRequest(request, cancellationToken);
158+
var message = new HttpMessage(request, new ResponseClassifier());
159+
160+
// Manually invoke the authentication policy's process method
161+
popTokenAuthenticationPolicy.ProcessAsync(message, ReadOnlyMemory<HttpPipelinePolicy>.Empty);
162+
// Run the thread in MTA.
163+
return interactiveBrowserCredential.Authenticate(new TokenRequestContext(authContext.Scopes), cancellationToken);
164+
});
165+
}
166+
else
167+
{
168+
authRecord = await Task.Run(() =>
169+
{
170+
// Run the thread in MTA.
171+
return interactiveBrowserCredential.Authenticate(new TokenRequestContext(authContext.Scopes), cancellationToken);
172+
});
173+
}
133174
}
134175
else
135176
{
@@ -447,4 +488,7 @@ public static Task DeleteAuthRecordAsync()
447488
return Task.CompletedTask;
448489
}
449490
}
491+
internal class PopClientOptions : ClientOptions
492+
{
493+
}
450494
}

0 commit comments

Comments
 (0)