Skip to content

Commit 15e22a9

Browse files
authored
Merge pull request #2072 from microsoftgraph/po/BumpToMSGraphCoreV3
Bump Microsoft.Graph.Core dependency to 3.x
2 parents 0b8a9f4 + fe7f76e commit 15e22a9

23 files changed

+462
-274
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@
44
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
55
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
66
<VersionPrefix>2.0.0</VersionPrefix>
7-
<VersionSuffix>preview7</VersionSuffix>
7+
<VersionSuffix>rc4</VersionSuffix>
88
</PropertyGroup>
99
<PropertyGroup>
1010
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1111
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Azure.Core" Version="1.25.0" />
15-
<PackageReference Include="Azure.Identity" Version="1.6.1" />
16-
<PackageReference Include="Microsoft.Graph.Core" Version="2.0.11" />
17-
<PackageReference Include="Microsoft.Identity.Client" Version="4.51.0" />
18-
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.27.0" />
19-
<!--Always ensure this version matches the versions of System.Security.Cryptography.* dependencies of Microsoft.Identity.Client when targeting PowerShell 6 and below.-->
20-
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="6.0.0" />
21-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
22-
<PackageReference Include="System.Text.Json" Version="6.0.5" />
23-
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
14+
<PackageReference Include="Azure.Identity" Version="1.9.0" />
15+
<PackageReference Include="Microsoft.Graph.Core" Version="3.0.7" />
16+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2417
</ItemGroup>
2518
<Target Name="CopyFiles" AfterTargets="Build">
2619
<Copy SourceFiles="@(PreLoadAssemblies)" DestinationFolder="$(OutputPath)/publish" />

src/Authentication/Authentication.Core/TokenCache/InMemoryTokenCache.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ public class InMemoryTokenCache
1010
{
1111
private InMemoryTokenCacheOptions InMemoryTokenCacheOptions { get; set; }
1212
protected byte[] _tokenCacheDataToFlush;
13+
14+
public InMemoryTokenCache()
15+
{
16+
InMemoryTokenCacheOptions = new InMemoryTokenCacheOptions();
17+
}
1318
public InMemoryTokenCache(byte[] tokenCache)
1419
{
1520
InMemoryTokenCacheOptions = new InMemoryTokenCacheOptions(tokenCache);
1621
}
1722

18-
public InMemoryTokenCache(InMemoryTokenCacheOptions options = null)
19-
{
20-
InMemoryTokenCacheOptions = options ?? new InMemoryTokenCacheOptions();
21-
}
2223
internal void UpdateTokenDataWithoutFlush(byte[] data)
2324
{
2425
_tokenCacheDataToFlush = data;
@@ -28,6 +29,7 @@ internal byte[] ReadTokenData()
2829
{
2930
return InMemoryTokenCacheOptions.TokenCache.ToArray();
3031
}
32+
3133
internal void FlushTokenData()
3234
{
3335
if (_tokenCacheDataToFlush != null)

src/Authentication/Authentication.Core/TokenCache/InMemoryTokenCacheOptions.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Microsoft.Graph.PowerShell.Authentication.Core.TokenCache
1212
{
13-
public class InMemoryTokenCacheOptions : UnsafeTokenCacheOptions
13+
internal class InMemoryTokenCacheOptions : UnsafeTokenCacheOptions
1414
{
1515
private readonly ReaderWriterLockSlim _sessionLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
1616
internal ReadOnlyMemory<byte> TokenCache { get; private set; }
@@ -19,6 +19,20 @@ public InMemoryTokenCacheOptions(ReadOnlyMemory<byte> token)
1919
{
2020
TokenCache = token;
2121
}
22+
23+
protected override async Task<TokenCacheData> RefreshCacheAsync(TokenCacheRefreshArgs args, CancellationToken cancellationToken = default)
24+
{
25+
_sessionLock.EnterReadLock();
26+
try
27+
{
28+
return await Task.FromResult(new TokenCacheData(TokenCache)).ConfigureAwait(false);
29+
}
30+
finally
31+
{
32+
_sessionLock.ExitReadLock();
33+
}
34+
}
35+
2236
protected override async Task<ReadOnlyMemory<byte>> RefreshCacheAsync()
2337
{
2438
_sessionLock.EnterReadLock();

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Azure.Core;
55
using Azure.Core.Diagnostics;
66
using Azure.Identity;
7+
using Microsoft.Graph.Authentication;
78
using Microsoft.Graph.PowerShell.Authentication.Core.Extensions;
89
using Microsoft.Identity.Client;
910
using Microsoft.Identity.Client.Extensions.Msal;
@@ -180,16 +181,16 @@ private static TokenCachePersistenceOptions GetTokenCachePersistenceOptions(IAut
180181
}
181182

182183
/// <summary>
183-
/// Gets a <see cref="IAuthenticationProvider"/> using the provided <see cref="IAuthContext"/>
184+
/// Gets a <see cref="AzureIdentityAccessTokenProvider"/> using the provided <see cref="IAuthContext"/>
184185
/// </summary>
185186
/// <param name="authContext">The <see cref="IAuthContext"/> to get a token credential for.</param>
186-
/// <returns>A <see cref="IAuthenticationProvider"/> based on provided <see cref="IAuthContext"/>.</returns>
187-
public static async Task<IAuthenticationProvider> GetAuthenticationProviderAsync(IAuthContext authContext)
187+
/// <returns>A <see cref="AzureIdentityAccessTokenProvider"/> based on provided <see cref="IAuthContext"/>.</returns>
188+
public static async Task<AzureIdentityAccessTokenProvider> GetAuthenticationProviderAsync(IAuthContext authContext)
188189
{
189190
if (authContext is null)
190191
throw new AuthenticationException(ErrorConstants.Message.MissingAuthContext);
191192
var tokenCrdential = await GetTokenCredentialAsync(authContext, default).ConfigureAwait(false);
192-
return new AzureIdentityAuthProvider(tokenCrdential, GetScopes(authContext));
193+
return new AzureIdentityAccessTokenProvider(credential: tokenCrdential, scopes: GetScopes(authContext));
193194
}
194195

195196
public static async Task<IAuthContext> AuthenticateAsync(IAuthContext authContext, CancellationToken cancellationToken)
@@ -396,7 +397,7 @@ private static bool TryFindCertificateBySubjectName(string subjectName, StoreLoc
396397
public static async Task<IAuthContext> LogoutAsync()
397398
{
398399
var authContext = GraphSession.Instance.AuthContext;
399-
GraphSession.Instance.InMemoryTokenCache.ClearCache();
400+
GraphSession.Instance.InMemoryTokenCache?.ClearCache();
400401
GraphSession.Instance.AuthContext = null;
401402
GraphSession.Instance.GraphHttpClient = null;
402403
await DeleteAuthRecordAsync().ConfigureAwait(false);

src/Authentication/Authentication.Core/Utilities/AzureIdentityAuthProvider.cs

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

src/Authentication/Authentication.Test/Handlers/HttpVersionHandlerTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using Microsoft.Graph.PowerShell.Authentication.Handlers;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Linq;
53
using System.Net.Http;
6-
using System.Text;
74
using System.Threading;
85
using System.Threading.Tasks;
96
using Xunit;
@@ -37,7 +34,9 @@ public async Task ShouldSetHttpMessageVersionTo2()
3734
// Assert
3835
Assert.NotNull(sentRequest);
3936
Assert.Equal(requestUrl, sentRequest.RequestUri);
37+
# if NET6_0_OR_GREATER
4038
Assert.Equal(sentRequest.Version, new Version(2, 0));
39+
# endif
4140
}
4241

4342
public void Dispose()

src/Authentication/Authentication.Test/Helpers/AuthenticationHelpersTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,23 @@ public AuthenticationHelpersTests()
3232
public async Task ShouldUseDelegateAuthProviderWhenUserAccessTokenIsProvidedAsync()
3333
{
3434
// Arrange
35-
string accessToken = "eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiVGVzdCIsIklzc3VlciI6Iklzc3VlciIsIlVzZXJuYW1lIjoiVGVzdCIsImV4cCI6MTY3ODQ4ODgxNiwiaWF0IjoxNjc4NDg4ODE2fQ.hpYypwHAV8H3jb4KuTiLpgLWy9A8H2d9HG7SxJ8Kpn0";
36-
GraphSession.Instance.InMemoryTokenCache = new InMemoryTokenCache(Encoding.UTF8.GetBytes(accessToken));
35+
string dummyAccessToken = "eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiVGVzdCIsIklzc3VlciI6Iklzc3VlciIsIlVzZXJuYW1lIjoiVGVzdCIsImV4cCI6MTY3ODQ4ODgxNiwiaWF0IjoxNjc4NDg4ODE2fQ.hpYypwHAV8H3jb4KuTiLpgLWy9A8H2d9HG7SxJ8Kpn0";
36+
GraphSession.Instance.InMemoryTokenCache = new InMemoryTokenCache(Encoding.UTF8.GetBytes(dummyAccessToken));
3737
AuthContext userProvidedAuthContext = new AuthContext
3838
{
3939
AuthType = AuthenticationType.UserProvidedAccessToken,
4040
ContextScope = ContextScope.Process
4141
};
4242

43-
IAuthenticationProvider authProvider = await AuthenticationHelpers.GetAuthenticationProviderAsync(userProvidedAuthContext);
44-
HttpRequestMessage requestMessage = new HttpRequestMessage();
43+
AzureIdentityAccessTokenProvider authProvider = await AuthenticationHelpers.GetAuthenticationProviderAsync(userProvidedAuthContext);
44+
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me");
4545

4646
// Act
47-
await authProvider.AuthenticateRequestAsync(requestMessage);
47+
var accessToken = await authProvider.GetAuthorizationTokenAsync(requestMessage.RequestUri);
4848

4949
// Assert
50-
Assert.IsType<AzureIdentityAuthProvider>(authProvider);
51-
Assert.Equal("Bearer", requestMessage.Headers.Authorization.Scheme);
52-
Assert.Equal(accessToken, requestMessage.Headers.Authorization.Parameter);
50+
Assert.IsType<AzureIdentityAccessTokenProvider>(authProvider);
51+
Assert.Equal(dummyAccessToken, accessToken);
5352

5453
// reset static instance.
5554
GraphSession.Reset();

src/Authentication/Authentication.Test/Microsoft.Graph.Authentication.Test.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
1010
<!-- As described in this post https://devblogs.microsoft.com/powershell/depending-on-the-right-powershell-nuget-package-in-your-net-project, reference the SDK for dotnetcore-->
1111
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.2" PrivateAssets="all" Condition="'$(TargetFramework)' == 'net6.0'" />
12-
<PackageReference Include="xunit" Version="2.4.1" />
13-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
12+
<PackageReference Include="xunit" Version="2.4.2" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="coverlet.collector" Version="3.1.2">
17+
<PackageReference Include="coverlet.collector" Version="6.0.0">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>

src/Authentication/Authentication.Test/TokenCache/InMemortyTokenCacheTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void InMemoryTokenCahceShouldHaveEmptyTokenCacheWhenInitialized()
2424
{
2525
GraphSession.Initialize(() => new GraphSession());
2626
GraphSession.Instance.InMemoryTokenCache = new InMemoryTokenCache();
27-
27+
2828
Assert.NotNull(GraphSession.Instance.InMemoryTokenCache);
2929
Assert.NotNull(GraphSession.Instance.InMemoryTokenCache.ReadTokenData());
3030
Assert.Empty(GraphSession.Instance.InMemoryTokenCache.ReadTokenData());
@@ -38,7 +38,7 @@ public void InMemoryTokenCahceShouldHaveInitializedTokenData()
3838
GraphSession.Initialize(() => new GraphSession());
3939
string mockCacheData = "mockCacheData";
4040
byte[] mockCacheDataBytes = Encoding.UTF8.GetBytes(mockCacheData);
41-
41+
4242
GraphSession.Instance.InMemoryTokenCache = new InMemoryTokenCache(mockCacheDataBytes);
4343
var cachedBytes = GraphSession.Instance.InMemoryTokenCache.ReadTokenData();
4444

@@ -57,7 +57,7 @@ public void UpdateTokenDataWithoutFlushShouldNotFlushInitializedTokenData()
5757
GraphSession.Initialize(() => new GraphSession());
5858
string mockCacheData = "intialTokenData";
5959
byte[] mockCacheDataBytes = Encoding.UTF8.GetBytes(mockCacheData);
60-
60+
6161
GraphSession.Instance.InMemoryTokenCache = new InMemoryTokenCache(mockCacheDataBytes);
6262
GraphSession.Instance.InMemoryTokenCache.UpdateTokenDataWithoutFlush(Encoding.UTF8.GetBytes("updatedTokenData"));
6363
var cachedBytes = GraphSession.Instance.InMemoryTokenCache.ReadTokenData();
@@ -70,14 +70,14 @@ public void UpdateTokenDataWithoutFlushShouldNotFlushInitializedTokenData()
7070

7171
GraphSession.Reset();
7272
}
73-
73+
7474
[Fact]
7575
public void UpdateTokenDataWithFlushShouldOverwroteInitializedTokenData()
7676
{
7777
GraphSession.Initialize(() => new GraphSession());
7878
string mockCacheData = "intialTokenData";
7979
byte[] mockCacheDataBytes = Encoding.UTF8.GetBytes(mockCacheData);
80-
80+
8181
GraphSession.Instance.InMemoryTokenCache = new InMemoryTokenCache(mockCacheDataBytes);
8282
string updatedTokenData = "updatedTokenData";
8383
byte[] updatedTokenDataBytes = Encoding.UTF8.GetBytes(updatedTokenData);
@@ -107,13 +107,13 @@ public void ClearCacheShouldClearInMemoeryTokenCache()
107107
GraphSession.Instance.InMemoryTokenCache.FlushTokenData();
108108
GraphSession.Instance.InMemoryTokenCache.ClearCache();
109109
var cachedBytes = GraphSession.Instance.InMemoryTokenCache.ReadTokenData();
110-
110+
111111

112112
Assert.NotNull(GraphSession.Instance.InMemoryTokenCache);
113113
Assert.NotNull(cachedBytes);
114114
Assert.Empty(cachedBytes);
115115

116116
GraphSession.Reset();
117-
}
117+
}
118118
}
119119
}

src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.Graph.PowerShell.Authentication.Helpers;
1111
using Microsoft.Graph.PowerShell.Authentication.Interfaces;
1212
using Microsoft.Graph.PowerShell.Authentication.Models;
13-
using Microsoft.Graph.PowerShell.Authentication.Utilities;
1413
using System;
1514
using System.Collections;
1615
using System.Collections.Generic;
@@ -331,7 +330,6 @@ public void OnImport()
331330
public void OnRemove(PSModuleInfo psModuleInfo)
332331
{
333332
GraphSession.Reset();
334-
DependencyAssemblyResolver.Reset();
335333
}
336334
}
337335
}

0 commit comments

Comments
 (0)