Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2727 from pnp/dev
Browse files Browse the repository at this point in the history
June 2020 Intermediate Release 2
  • Loading branch information
erwinvanhunen authored Jun 11, 2020
2 parents b812c37 + c297004 commit 48d8da9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
60 changes: 31 additions & 29 deletions Commands/Base/PnPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class PnPConnection
/// Indication for telemetry through which method a connection has been established
/// </summary>
public InitializationType InitializationType { get; protected set; }

/// <summary>
/// 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.
/// </summary>
public int? MinimalHealthScore { get; protected set; }

public int RetryCount { get; protected set; }
public int RetryWait { get; protected set; }
public PSCredential PSCredential { get; protected set; }
Expand Down Expand Up @@ -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;
}
Expand All @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -224,29 +224,29 @@ internal void ClearTokens()
/// <param name="minimalHealthScore">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.</param>
/// <param name="pnpVersionTag">Identifier set on the SharePoint ClientContext as the ClientTag to identify the source of the requests to SharePoint. Leave NULL not to set it.</param>
/// <param name="disableTelemetry">Boolean indicating if telemetry on the commands being executed should be disabled. Telemetry is enabled by default.</param>
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<TokenAudience, GenericToken> tokens = null,
int? minimalHealthScore = null,
string pnpVersionTag = null,
string pnpVersionTag = null,
bool disableTelemetry = false)
{
if (!disableTelemetry)
{
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
if (tokens != null)
{
AccessTokens.AddRange(tokens);
}

// Validate if we have a SharePoint Context
if (Context != null)
{
Expand Down Expand Up @@ -295,7 +295,7 @@ private PnPConnection(PSHost host,
/// <param name="pnpVersionTag">Identifier set on the SharePoint ClientContext as the ClientTag to identify the source of the requests to SharePoint. Leave NULL not to set it.</param>
/// <param name="disableTelemetry">Boolean indicating if telemetry on the commands being executed should be disabled. Telemetry is enabled by default.</param>
/// <returns><see cref="PnPConnection"/ instance which can be used to communicate with one of the supported APIs</returns>
public static PnPConnection GetConnectionWithClientIdAndClientSecret(string clientId,
public static PnPConnection GetConnectionWithClientIdAndClientSecret(string clientId,
string clientSecret,
PSHost host,
InitializationType initializationType,
Expand Down Expand Up @@ -329,7 +329,7 @@ public static PnPConnection GetConnectionWithClientIdAndClientSecret(string clie
/// <param name="pnpVersionTag">Identifier set on the SharePoint ClientContext as the ClientTag to identify the source of the requests to SharePoint. Leave NULL not to set it.</param>
/// <param name="disableTelemetry">Boolean indicating if telemetry on the commands being executed should be disabled. Telemetry is enabled by default.</param>
/// <returns><see cref="PnPConnection"/ instance which can be used to communicate with one of the supported APIs</returns>
public static PnPConnection GetConnectionWithClientIdAndCertificate(string clientId,
public static PnPConnection GetConnectionWithClientIdAndCertificate(string clientId,
X509Certificate2 certificate,
PSHost host,
InitializationType initializationType,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
};
}

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Commands/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.22.2006.1
3.22.2006.2

0 comments on commit 48d8da9

Please sign in to comment.