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

Commit c781588

Browse files
Merge pull request #2858 from pnp/dev
August 2020 Point Release
2 parents 6323c6a + 60f5c0c commit c781588

25 files changed

+327
-223
lines changed
512 Bytes
Binary file not shown.
-8 Bytes
Binary file not shown.

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
77

8+
## [3.25.2009.0]
9+
10+
### Added
11+
- Added -AzureEnvironment parameter to `Initialize-PnPPowerShellAuthentication` to create an Azure AD App in other Azure environments than the default one.
12+
- Added -AzureEnvironment parameter to all Connect-PnPOnline options which result in an OAuth based authentication connection, supporting the various Azure Environments available.
13+
14+
### Changed
15+
- Fixed issue with Submit-PnPTeamsChannelMessage not posting HTML message when setting the content type to Html.
16+
- The content type that Submit-PnPTeamsChannelMessage uses defaults now to HTML.
17+
- Fixed an issue with the PnP Provisioning Engine not being able to correctly acquire a token for the Microsoft Graph when provisioning a tenant template containing a Team.
18+
- Optimized Submit-PnPSearchQuery and Get-PnPSiteSearchQueryResults cmdlets when using the -All parameter.
19+
- Fixed TrimDuplicates to be default off for Submit-PnPSearchQuery
20+
21+
### Contributors
22+
23+
824
## [3.24.2008.0]
925

1026
### Added

Commands/Base/ConnectOnline.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ public class ConnectOnline : BasePSCmdlet
522522
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_APPONLYAADCER, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")]
523523
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_TOKEN, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")]
524524
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_APPONLYCLIENTIDCLIENTSECRETURL, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")]
525+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_AADWITHSCOPE, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")]
526+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_DEVICELOGIN, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")]
527+
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_GRAPHDEVICELOGIN, HelpMessage = "The Azure environment to use for authentication, the defaults to 'Production' which is the main Azure environment.")]
525528
public AzureEnvironment AzureEnvironment = AzureEnvironment.Production;
526529

527530
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_AADWITHSCOPE, HelpMessage = "The array of permission scopes to request from Azure Active Directory")]
@@ -710,7 +713,7 @@ protected void Connect()
710713
break;
711714

712715
case ParameterSet_AADWITHSCOPE:
713-
connection = ConnectAadWithScope(credentials);
716+
connection = ConnectAadWithScope(credentials, AzureEnvironment);
714717
break;
715718
case ParameterSet_ACCESSTOKEN:
716719
connection = ConnectAccessToken();
@@ -889,7 +892,7 @@ private PnPConnection ConnectDeviceLogin()
889892
{
890893
Url += "/";
891894
}
892-
var connection = PnPConnectionHelper.InstantiateDeviceLoginConnection(Url, LaunchBrowser, MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, TenantAdminUrl, Host, NoTelemetry);
895+
var connection = PnPConnectionHelper.InstantiateDeviceLoginConnection(Url, LaunchBrowser, MinimalHealthScore, RetryCount, RetryWait, RequestTimeout, TenantAdminUrl, Host, NoTelemetry, AzureEnvironment);
893896

894897
if (Host.Name == "ConsoleHost")
895898
{
@@ -939,7 +942,7 @@ private PnPConnection ConnectGraphDeviceLogin(string accessToken)
939942
}
940943
}
941944
return false;
942-
}, Host, NoTelemetry);
945+
}, Host, NoTelemetry, AzureEnvironment);
943946
if (Host.Name == "ConsoleHost")
944947
{
945948
Console.TreatControlCAsInput = ctrlCAsInput;
@@ -1076,7 +1079,7 @@ private PnPConnection ConnectAppOnlyAadCer()
10761079
/// </summary>
10771080
/// <param name="credentials">Credentials to authenticate with for delegated access or NULL for application permissions</param>
10781081
/// <returns>PnPConnection based on the parameters provided in the parameter set</returns>
1079-
private PnPConnection ConnectAadWithScope(PSCredential credentials)
1082+
private PnPConnection ConnectAadWithScope(PSCredential credentials, AzureEnvironment azureEnvironment)
10801083
{
10811084
#if !ONPREMISES
10821085
// Filter out the scopes for the Microsoft Office 365 Management API
@@ -1100,7 +1103,7 @@ private PnPConnection ConnectAadWithScope(PSCredential credentials)
11001103
// TokenManager.InitializeAsync(TokenManager.CLIENTID_PNPMANAGEMENTSHELL, officeManagementApiScopes.Select(s => $"https://manage.office.com/{s}").ToArray(), credentials.UserName, credentials.Password, cacheIdentifierName: "OfficeManagementApi").GetAwaiter().GetResult();
11011104
//}
11021105

1103-
var officeManagementApiToken = credentials == null ? OfficeManagementApiToken.AcquireApplicationTokenInteractive(PnPConnection.PnPManagementShellClientId, officeManagementApiScopes) : OfficeManagementApiToken.AcquireDelegatedTokenWithCredentials(PnPConnection.PnPManagementShellClientId, officeManagementApiScopes, credentials.UserName, credentials.Password);
1106+
var officeManagementApiToken = credentials == null ? OfficeManagementApiToken.AcquireApplicationTokenInteractive(PnPConnection.PnPManagementShellClientId, officeManagementApiScopes, azureEnvironment) : OfficeManagementApiToken.AcquireDelegatedTokenWithCredentials(PnPConnection.PnPManagementShellClientId, officeManagementApiScopes, credentials.UserName, credentials.Password, azureEnvironment);
11041107
#else
11051108
var officeManagementApiToken = credentials == null ? OfficeManagementApiToken.AcquireApplicationTokenDeviceLogin(PnPConnection.PnPManagementShellClientId, officeManagementApiScopes, PnPConnection.DeviceLoginCallback(this.Host, true)) : OfficeManagementApiToken.AcquireDelegatedTokenWithCredentials(PnPConnection.PnPManagementShellClientId, officeManagementApiScopes, credentials.UserName, credentials.Password);
11061109
#endif
@@ -1111,7 +1114,7 @@ private PnPConnection ConnectAadWithScope(PSCredential credentials)
11111114
if (graphScopes.Length > 0)
11121115
{
11131116
#if !PNPPSCORE
1114-
var graphToken = credentials == null ? GraphToken.AcquireApplicationTokenInteractive(PnPConnection.PnPManagementShellClientId, graphScopes) : GraphToken.AcquireDelegatedTokenWithCredentials(PnPConnection.PnPManagementShellClientId, graphScopes, credentials.UserName, credentials.Password);
1117+
var graphToken = credentials == null ? GraphToken.AcquireApplicationTokenInteractive(PnPConnection.PnPManagementShellClientId, graphScopes, azureEnvironment) : GraphToken.AcquireDelegatedTokenWithCredentials(PnPConnection.PnPManagementShellClientId, graphScopes, credentials.UserName, credentials.Password, azureEnvironment);
11151118
#else
11161119
var graphToken = credentials == null ? GraphToken.AcquireApplicationTokenDeviceLogin(PnPConnection.PnPManagementShellClientId, graphScopes, PnPConnection.DeviceLoginCallback(this.Host, true)) : GraphToken.AcquireDelegatedTokenWithCredentials(PnPConnection.PnPManagementShellClientId, graphScopes, credentials.UserName, credentials.Password);
11171120
#endif
@@ -1341,6 +1344,11 @@ private PnPConnection ConnectCredentials(PSCredential credentials)
13411344
RequestTimeout,
13421345
TenantAdminUrl,
13431346
NoTelemetry,
1347+
#if !ONPREMISES
1348+
AzureEnvironment,
1349+
#else
1350+
AzureEnvironment.Production,
1351+
#endif
13441352
SkipTenantAdminCheck,
13451353
AuthenticationMode);
13461354
#else

Commands/Base/InitializePowerShellAuthentication.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if !ONPREMISES && !PNPPSCORE
2+
using OfficeDevPnP.Core;
23
using OfficeDevPnP.Core.Utilities;
34
using PnP.PowerShell.CmdletHelpAttributes;
45
using PnP.PowerShell.Commands.Model;
@@ -87,10 +88,18 @@ public class InitializePowerShellAuthentication : BasePSCmdlet, IDynamicParamete
8788
[Parameter(Mandatory = false, HelpMessage = "Local Certificate Store to add the certificate to", ParameterSetName = ParameterSet_NEWCERT)]
8889
public StoreLocation Store;
8990

91+
[Parameter(Mandatory = false, HelpMessage = "Specify the Azure environment to use to setup the Azure AD app. Defaults to 'Production'.")]
92+
public AzureEnvironment AzureEnvironment = AzureEnvironment.Production;
93+
9094
protected override void ProcessRecord()
9195
{
96+
var loginEndPoint = string.Empty;
9297
var record = new PSObject();
93-
var token = AzureAuthHelper.AuthenticateAsync(Tenant).GetAwaiter().GetResult();
98+
using (var authenticationManager = new AuthenticationManager())
99+
{
100+
loginEndPoint = authenticationManager.GetAzureADLoginEndPoint(AzureEnvironment);
101+
}
102+
var token = AzureAuthHelper.AuthenticateAsync(Tenant, loginEndPoint).GetAwaiter().GetResult();
94103

95104
var cert = new X509Certificate2();
96105
if (ParameterSetName == ParameterSet_EXISTINGCERT)
@@ -104,7 +113,7 @@ protected override void ProcessRecord()
104113
if (ParameterSpecified(nameof(CertificatePassword)))
105114
{
106115
try
107-
{
116+
{
108117
cert.Import(CertificatePath, CertificatePassword, X509KeyStorageFlags.Exportable);
109118
}
110119
catch (CryptographicException e) when (e.Message.Contains("The specified network password is not correct"))
@@ -118,7 +127,7 @@ protected override void ProcessRecord()
118127
{
119128
cert.Import(CertificatePath);
120129
}
121-
catch(CryptographicException e) when (e.Message.Contains("The specified network password is not correct"))
130+
catch (CryptographicException e) when (e.Message.Contains("The specified network password is not correct"))
122131
{
123132
throw new PSArgumentNullException(nameof(CertificatePassword), string.Format(Resources.PrivateKeyCertificateImportFailedPasswordMissing, nameof(CertificatePassword)));
124133
}
@@ -177,7 +186,7 @@ protected override void ProcessRecord()
177186
}
178187
if (ParameterSpecified(nameof(Store)))
179188
{
180-
using (var store = new X509Store("My",Store))
189+
using (var store = new X509Store("My", Store))
181190
{
182191
store.Open(OpenFlags.ReadWrite);
183192
store.Add(cert);
@@ -228,7 +237,7 @@ protected override void ProcessRecord()
228237
publicClient = new
229238
{
230239
redirectUris = new[] {
231-
"https://login.microsoftonline.com/common/oauth2/nativeclient",
240+
$"{loginEndPoint}/common/oauth2/nativeclient"
232241
}
233242
},
234243
requiredResourceAccess = scopesPayload
@@ -239,9 +248,9 @@ protected override void ProcessRecord()
239248

240249
var waitTime = 60;
241250
Host.UI.Write(ConsoleColor.Yellow, Host.UI.RawUI.BackgroundColor, $"Waiting {waitTime} seconds to launch consent flow in a browser window. This wait is required to make sure that Azure AD is able to initialize all required artifacts.");
242-
251+
243252
Console.TreatControlCAsInput = true;
244-
253+
245254
for (var i = 0; i < waitTime; i++)
246255
{
247256
Host.UI.Write(ConsoleColor.Yellow, Host.UI.RawUI.BackgroundColor, ".");
@@ -251,24 +260,24 @@ protected override void ProcessRecord()
251260
if (Host.UI.RawUI.KeyAvailable)
252261
{
253262
var key = Host.UI.RawUI.ReadKey(ReadKeyOptions.AllowCtrlC | ReadKeyOptions.NoEcho | ReadKeyOptions.IncludeKeyUp);
254-
if((key.ControlKeyState.HasFlag(ControlKeyStates.LeftCtrlPressed) || key.ControlKeyState.HasFlag(ControlKeyStates.RightCtrlPressed)) && key.VirtualKeyCode == 67)
263+
if ((key.ControlKeyState.HasFlag(ControlKeyStates.LeftCtrlPressed) || key.ControlKeyState.HasFlag(ControlKeyStates.RightCtrlPressed)) && key.VirtualKeyCode == 67)
255264
{
256-
265+
257266
break;
258267
}
259268
}
260269
}
261270
Host.UI.WriteLine();
262271

263-
var consentUrl = $"https://login.microsoftonline.com/{Tenant}/v2.0/adminconsent?client_id={azureApp.AppId}&scope=https://microsoft.sharepoint-df.com/.default";
272+
var consentUrl = $"{loginEndPoint}/{Tenant}/v2.0/adminconsent?client_id={azureApp.AppId}&scope=https://microsoft.sharepoint-df.com/.default";
264273
record.Properties.Add(new PSVariableProperty(new PSVariable("Certificate Thumbprint", cert.GetCertHashString())));
265274

266275
WriteObject(record);
267276

268277
AzureAuthHelper.OpenConsentFlow(consentUrl, (message) =>
269278
{
270279
Host.UI.WriteLine(ConsoleColor.Red, Host.UI.RawUI.BackgroundColor, message);
271-
});
280+
});
272281
}
273282
}
274283

0 commit comments

Comments
 (0)