Skip to content

Commit

Permalink
Resolve dependency conflict with Az module. (#1894)
Browse files Browse the repository at this point in the history
* Resolve dependency conflict with Az module.

* Default to Process ContextScope when on WSL
  • Loading branch information
peombwa authored Mar 23, 2023
1 parent 9cd80d9 commit 57ea819
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix>preview5</VersionSuffix>
<VersionSuffix>preview7</VersionSuffix>
</PropertyGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.28.0" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Microsoft.Graph.Core" Version="2.0.15" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.50.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.26.0" />
<PackageReference Include="Azure.Core" Version="1.25.0" />
<PackageReference Include="Azure.Identity" Version="1.6.1" />
<PackageReference Include="Microsoft.Graph.Core" Version="2.0.11" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.51.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.27.0" />
<!--Always ensure this version matches the versions of System.Security.Cryptography.* dependencies of Microsoft.Identity.Client when targeting PowerShell 6 and below.-->
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="7.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
<Target Name="CopyFiles" AfterTargets="Build">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using Microsoft.Graph.PowerShell.Authentication.Core.Models;
using Microsoft.Graph.PowerShell.Authentication.Models;
using Microsoft.Identity.Client;
using Newtonsoft.Json;
using System;
using System.Globalization;
using System.Text;
using System.Text.Json;

namespace Microsoft.Graph.PowerShell.Authentication.Core.Utilities
{
Expand Down Expand Up @@ -64,7 +64,7 @@ internal static T DecodeToObject<T>(string jwtString)
var decodedJWT = DecodeJWT(jwtString);
if (string.IsNullOrWhiteSpace(decodedJWT?.Payload))
return default;
return JsonConvert.DeserializeObject<T>(decodedJWT.Payload);
return JsonSerializer.Deserialize<T>(decodedJWT.Payload);
}
catch (Exception ex)
{
Expand Down
14 changes: 12 additions & 2 deletions src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Graph.PowerShell.Authentication.Core.Extensions;
using Microsoft.Graph.PowerShell.Authentication.Core.TokenCache;
using Microsoft.Graph.PowerShell.Authentication.Core.Utilities;
using Microsoft.Graph.PowerShell.Authentication.Extensions;
using Microsoft.Graph.PowerShell.Authentication.Helpers;
using Microsoft.Graph.PowerShell.Authentication.Interfaces;
using Microsoft.Graph.PowerShell.Authentication.Models;
Expand All @@ -15,6 +16,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
Expand Down Expand Up @@ -177,8 +179,16 @@ private async Task ProcessRecordAsync()
authContext.AuthType = AuthenticationType.Delegated;
string[] processedScopes = ProcessScopes(Scopes);
authContext.Scopes = !processedScopes.Any() ? new[] { "User.Read" } : processedScopes;
// Default to CurrentUser but allow the customer to change this via `-ContextScope`.
authContext.ContextScope = this.IsParameterBound(nameof(ContextScope)) ? ContextScope : ContextScope.CurrentUser;
if (RuntimeInformation.OSDescription.ContainsValue("WSL", StringComparison.InvariantCulture))
{
// Use process scope when on WSL. WSL does not have secret service that's used to cache tokens on Linux, see https://github.com/microsoft/WSL/issues/4254.
authContext.ContextScope = ContextScope.Process;
}
else
{
// Default to CurrentUser but allow the customer to change this via `-ContextScope`.
authContext.ContextScope = this.IsParameterBound(nameof(ContextScope)) ? ContextScope : ContextScope.CurrentUser;
}
authContext.TokenCredentialType = UseDeviceCode ? TokenCredentialType.DeviceCode : TokenCredentialType.InteractiveBrowser;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<NuspecFile>Microsoft.Graph.Authentication.nuspec</NuspecFile>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionSuffix>preview5</VersionSuffix>
<VersionSuffix>preview7</VersionSuffix>
</PropertyGroup>
<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package>
<metadata>
<version>2.0.0-preview5</version>
<version>2.0.0-preview7</version>
<id>Microsoft.Graph.Authentication</id>
<description>Microsoft Graph PowerShell authentication module</description>
<authors>Microsoft</authors>
Expand All @@ -25,6 +25,21 @@
<file src="artifacts\StartupScripts\" target="StartupScripts" />
<file src="artifacts\custom\" target="custom" />
<!-- Copy framework dependent assemblies to respective framework directory. -->
<!-- Shared -->
<file src="artifacts\Dependencies\Azure.Core.dll" target="Dependencies" />
<file src="artifacts\Dependencies\Azure.Identity.dll" target="Dependencies" />
<file src="artifacts\Dependencies\Microsoft.Bcl.AsyncInterfaces.dll" target="Dependencies" />
<file src="artifacts\Dependencies\Microsoft.Identity.Client.Extensions.Msal.dll" target="Dependencies" />
<file src="artifacts\Dependencies\Microsoft.IdentityModel.Abstractions.dll" target="Dependencies" />
<file src="artifacts\Dependencies\Newtonsoft.Json.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Buffers.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Diagnostics.DiagnosticSource.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Memory.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Numerics.Vectors.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Runtime.CompilerServices.Unsafe.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Text.Encodings.Web.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Text.Json.dll" target="Dependencies" />
<file src="artifacts\Dependencies\System.Threading.Tasks.Extensions.dll" target="Dependencies" />
<!-- Core-->
<file src="artifacts\Dependencies\Core\Azure.Core.dll" target="Dependencies\Core" />
<file src="artifacts\Dependencies\Core\Azure.Identity.dll" target="Dependencies\Core" />
Expand All @@ -35,23 +50,9 @@
<file src="artifacts\Dependencies\Core\Newtonsoft.Json.dll" target="Dependencies\Core" />
<file src="artifacts\Dependencies\Core\System.Security.Cryptography.ProtectedData.dll" target="Dependencies\Core" />
<!-- Desktop -->
<file src="artifacts\Dependencies\Desktop\Azure.Core.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Azure.Identity.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Microsoft.Bcl.AsyncInterfaces.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Microsoft.Graph.Core.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Microsoft.Identity.Client.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Microsoft.Identity.Client.Extensions.Msal.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Microsoft.IdentityModel.Abstractions.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\Newtonsoft.Json.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Buffers.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Diagnostics.DiagnosticSource.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Memory.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Net.Http.WinHttpHandler.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Numerics.Vectors.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Runtime.CompilerServices.Unsafe.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Security.Cryptography.ProtectedData.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Text.Encodings.Web.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Text.Json.dll" target="Dependencies\Desktop" />
<file src="artifacts\Dependencies\Desktop\System.Threading.Tasks.Extensions.dll" target="Dependencies\Desktop" />
</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft
#
# Generated on: 3/10/2023
# Generated on: 3/22/2023
#

@{
Expand Down Expand Up @@ -114,7 +114,7 @@ PrivateData = @{
ReleaseNotes = 'See https://aka.ms/GraphPowerShell-Release.'

# Prerelease string of this module
Prerelease = 'preview5'
Prerelease = 'preview7'

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (Test-Path -Path "$PSScriptRoot\StartupScripts" -ErrorAction Ignore)
Export-ModuleMember -Cmdlet (Get-ModuleCmdlet -ModulePath $ModulePath) -Alias (Get-ModuleCmdlet -ModulePath $ModulePath -AsAlias)

$DependencyPath = (Join-Path $PSScriptRoot -ChildPath "Dependencies")
if (Test-Path $DependencyPath -ErrorAction Ignore)
if ((Test-Path $DependencyPath -ErrorAction Ignore) -and ($PSEdition -eq "Desktop"))
{
try
{
Expand Down

0 comments on commit 57ea819

Please sign in to comment.