From ba472f1a40297fe7832ce5fc1df4abbe29a531b4 Mon Sep 17 00:00:00 2001 From: Erwin van Hunen Date: Wed, 10 Jun 2020 12:52:20 +0200 Subject: [PATCH 1/3] fixes issue with -PnPO365ManagementShell parameter and access denied messages --- Commands/Base/PnPConnection.cs | 60 +++++++++++++++-------------- Commands/Properties/AssemblyInfo.cs | 4 +- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Commands/Base/PnPConnection.cs b/Commands/Base/PnPConnection.cs index 924ce174c..37f8a8dc9 100644 --- a/Commands/Base/PnPConnection.cs +++ b/Commands/Base/PnPConnection.cs @@ -49,12 +49,12 @@ public class PnPConnection /// Indication for telemetry through which method a connection has been established /// public InitializationType InitializationType { get; protected set; } - + /// /// If provided, it defines the minimal health score the SharePoint server should return back before executing requests on it. Use scale 0 - 10 where 0 is most health and 10 is least healthy. If set to NULL, no health score check will take place. /// public int? MinimalHealthScore { get; protected set; } - + public int RetryCount { get; protected set; } public int RetryWait { get; protected set; } public PSCredential PSCredential { get; protected set; } @@ -130,7 +130,7 @@ internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] roles = if (token.ExpiresOn > DateTime.Now) { // Token is still valid, ensure we dont have specific roles to check for or the requested roles to execute the command are present in the token - if(roles == null || roles.Length == 0 || roles.Any(r => token.Roles.Contains(r))) + if (roles == null || roles.Length == 0 || roles.Any(r => token.Roles.Contains(r))) { return token; } @@ -146,7 +146,7 @@ internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] roles = } // We do not have a token for the requested audience yet or it was no longer valid, try to create (a new) one - switch(tokenAudience) + switch (tokenAudience) { case TokenAudience.MicrosoftGraph: if (!string.IsNullOrEmpty(Tenant)) @@ -181,7 +181,7 @@ internal GenericToken TryGetToken(TokenAudience tokenAudience, string[] roles = return null; } - if(token != null) + if (token != null) { // Managed to create a token for the requested audience, add it to our collection with tokens AccessTokens[tokenAudience] = token; @@ -224,13 +224,13 @@ internal void ClearTokens() /// Minimum health score that the SharePoint server should report before allowing requests to be executed on it. Scale of 0 to 10 where 0 is healthiest and 10 is least healthy. Leave NULL not to perform health checks on SharePoint. /// Identifier set on the SharePoint ClientContext as the ClientTag to identify the source of the requests to SharePoint. Leave NULL not to set it. /// Boolean indicating if telemetry on the commands being executed should be disabled. Telemetry is enabled by default. - private PnPConnection(PSHost host, - InitializationType initializationType, - string url = null, - ClientContext clientContext = null, + private PnPConnection(PSHost host, + InitializationType initializationType, + string url = null, + ClientContext clientContext = null, Dictionary tokens = null, int? minimalHealthScore = null, - string pnpVersionTag = null, + string pnpVersionTag = null, bool disableTelemetry = false) { if (!disableTelemetry) @@ -238,7 +238,7 @@ private PnPConnection(PSHost host, InitializeTelemetry(clientContext, host, initializationType); } - UserAgent = $"NONISV|SharePointPnP|PnPPS/{((AssemblyFileVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version}"; + UserAgent = $"NONISV|SharePointPnP|PnPPS/{((AssemblyFileVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version}"; Context = clientContext; // Enrich the AccessTokens collection with the token(s) passed in @@ -246,7 +246,7 @@ private PnPConnection(PSHost host, { AccessTokens.AddRange(tokens); } - + // Validate if we have a SharePoint Context if (Context != null) { @@ -295,7 +295,7 @@ private PnPConnection(PSHost host, /// Identifier set on the SharePoint ClientContext as the ClientTag to identify the source of the requests to SharePoint. Leave NULL not to set it. /// Boolean indicating if telemetry on the commands being executed should be disabled. Telemetry is enabled by default. /// - public static PnPConnection GetConnectionWithClientIdAndClientSecret(string clientId, + public static PnPConnection GetConnectionWithClientIdAndClientSecret(string clientId, string clientSecret, PSHost host, InitializationType initializationType, @@ -329,7 +329,7 @@ public static PnPConnection GetConnectionWithClientIdAndClientSecret(string clie /// Identifier set on the SharePoint ClientContext as the ClientTag to identify the source of the requests to SharePoint. Leave NULL not to set it. /// Boolean indicating if telemetry on the commands being executed should be disabled. Telemetry is enabled by default. /// - public static PnPConnection GetConnectionWithClientIdAndCertificate(string clientId, + public static PnPConnection GetConnectionWithClientIdAndCertificate(string clientId, X509Certificate2 certificate, PSHost host, InitializationType initializationType, @@ -364,7 +364,7 @@ public static PnPConnection GetConnectionWithClientIdAndCertificate(string clien public static PnPConnection GetConnectionWithPsCredential(PSCredential credential, PSHost host, InitializationType initializationType, - string url = null, + string url = null, ClientContext clientContext = null, int? minimalHealthScore = null, string pnpVersionTag = null, @@ -419,17 +419,17 @@ internal PnPConnection(ClientContext context, ConnectionType connectionType, int ClientSecret = clientSecret; } - internal PnPConnection(ClientContext context, - ConnectionType connectionType, - int minimalHealthScore, - int retryCount, - int retryWait, - PSCredential credential, - string url, - string tenantAdminUrl, - string pnpVersionTag, - PSHost host, - bool disableTelemetry, + internal PnPConnection(ClientContext context, + ConnectionType connectionType, + int minimalHealthScore, + int retryCount, + int retryWait, + PSCredential credential, + string url, + string tenantAdminUrl, + string pnpVersionTag, + PSHost host, + bool disableTelemetry, InitializationType initializationType) { if (!disableTelemetry) @@ -442,7 +442,7 @@ internal PnPConnection(ClientContext context, // throw new ArgumentNullException(nameof(context)); Context = context; Context.ExecutingWebRequest += Context_ExecutingWebRequest; - + ConnectionType = connectionType; MinimalHealthScore = minimalHealthScore; RetryCount = retryCount; @@ -478,10 +478,12 @@ internal PnPConnection(ClientContext context, GenericToken tokenResult, Connecti PnPVersionTag = pnpVersionTag; Url = (new Uri(url)).AbsoluteUri; ConnectionMethod = ConnectionMethod.AccessToken; + ClientId = DeviceLoginClientId; + Tenant = tokenResult.ParsedToken.Claims.FirstOrDefault(c => c.Type == "tid").Value; context.ExecutingWebRequest += (sender, args) => { args.WebRequestExecutor.WebRequest.UserAgent = UserAgent; - args.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + CurrentConnection.TryGetAccessToken(TokenAudience.MicrosoftGraph); + args.WebRequestExecutor.RequestHeaders["Authorization"] = "Bearer " + tokenResult.AccessToken; }; } @@ -552,7 +554,7 @@ internal ClientContext CloneContext(string url) if ((ex is WebException || ex is NotSupportedException) && CurrentConnection.PSCredential != null) { // legacy auth? - using(var authManager = new OfficeDevPnP.Core.AuthenticationManager()) + using (var authManager = new OfficeDevPnP.Core.AuthenticationManager()) { context = authManager.GetAzureADCredentialsContext(url.ToString(), CurrentConnection.PSCredential.UserName, CurrentConnection.PSCredential.Password); } diff --git a/Commands/Properties/AssemblyInfo.cs b/Commands/Properties/AssemblyInfo.cs index c3a6d22b2..b65336ad1 100644 --- a/Commands/Properties/AssemblyInfo.cs +++ b/Commands/Properties/AssemblyInfo.cs @@ -48,6 +48,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.22.2006.1")] -[assembly: AssemblyFileVersion("3.22.2006.1")] +[assembly: AssemblyVersion("3.22.2006.2")] +[assembly: AssemblyFileVersion("3.22.2006.2")] [assembly: InternalsVisibleTo("SharePointPnP.PowerShell.Tests")] \ No newline at end of file From d41a6d9def1a2df71d230679761128162bace962 Mon Sep 17 00:00:00 2001 From: Erwin van Hunen Date: Thu, 11 Jun 2020 18:17:03 +0200 Subject: [PATCH 2/3] June 2020 Intermediate Release 2 --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 2fb930e9c..df7248568 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.22.2006.1 \ No newline at end of file +3.22.2006.2 \ No newline at end of file From c297004ef273ae794e2bfc1958ac88b1963a9117 Mon Sep 17 00:00:00 2001 From: Erwin van Hunen Date: Thu, 11 Jun 2020 19:00:21 +0200 Subject: [PATCH 3/3] June 2020 Intermediate Release 2 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5c340e62..c6c3f1998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Contributors +## [3.22.2006.2] + +Intermediate release due to a fix in the underlying Core Library and the Connect-PnPOnline cmdlet. + ## [3.22.2006.1] Intermediate release due to a fix in the underlying Core Library.