Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 905afa3

Browse files
author
Isaiah Williams
authored
Partner cmdlet feature update (#249)
1 parent 676ad42 commit 905afa3

120 files changed

Lines changed: 2263 additions & 2226 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020

2121
# Change Log
2222

23+
## Upcoming Release
24+
25+
* Authentication
26+
* Addressed an issue where NullReferenceException exception was being encountered when invoking [Connect-PartnerCenter](https://docs.microsoft.com/powershell/module/partnercenter/Connect-PartnerCenter) using a certificate
27+
* Addressed an issue where NullReferenceException exception was being encountered when invoking [New-PartnerAccessToken](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerAccessToken) using a certificate
28+
* Defined the refresh token parameter set for the [New-PartnerAccessToken](https://docs.microsoft.com/powershell/module/partnercenter/New-PartnerAccessToken) command to make it easier to ensure all the appropriate parameters have been specified when exchanging a refresh token for an access token
29+
* Module
30+
* All commands now perform operations asynchronously
31+
2332
## 3.0.3 - December 2019
2433

2534
* Authentication

docs/help/Connect-PartnerCenter.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ Connect-PartnerCenter -AccessToken <String> [-Environment <EnvironmentName>] [-T
2828

2929
### RefreshToken
3030
```powershell
31-
Connect-PartnerCenter -ApplicationId <String> [-CertificateThumbprint <String>] [-Credential <PSCredential>]
32-
[-Environment <EnvironmentName>] -RefreshToken <String> [-Tenant <String>] [-WhatIf] [-Confirm]
33-
[<CommonParameters>]
31+
Connect-PartnerCenter -ApplicationId <String> [-Credential <PSCredential>] [-Environment <EnvironmentName>]
32+
-RefreshToken <String> [-Tenant <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
3433
```
3534

3635
### ServicePrincipalCertificate
@@ -122,18 +121,6 @@ Accept wildcard characters: False
122121
### -CertificateThumbprint
123122
Certificate Hash (Thumbprint)
124123
125-
```yaml
126-
Type: String
127-
Parameter Sets: RefreshToken
128-
Aliases:
129-
130-
Required: False
131-
Position: Named
132-
Default value: None
133-
Accept pipeline input: False
134-
Accept wildcard characters: False
135-
```
136-
137124
```yaml
138125
Type: String
139126
Parameter Sets: ServicePrincipalCertificate

docs/help/Get-PartnerCustomerUser.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@ Gets a list of all customer users or a specified user for the tenant.
1616

1717
### ByCustomerId (Default)
1818
```powershell
19-
Get-PartnerCustomerUser [-CustomerId] <String> [-ReturnDeletedUsers] [<CommonParameters>]
19+
Get-PartnerCustomerUser [-CustomerId] <String> [<CommonParameters>]
2020
```
2121

2222
### ByUserId
2323
```powershell
2424
Get-PartnerCustomerUser [-CustomerId] <String> -UserId <String> [<CommonParameters>]
2525
```
2626

27+
### ByUserState
28+
```powershell
29+
Get-PartnerCustomerUser [-CustomerId] <String> [-ReturnDeletedUsers] [<CommonParameters>]
30+
```
31+
2732
### ByUpn
2833
```powershell
2934
Get-PartnerCustomerUser [-CustomerId] <String> -UserPrincipalName <String> [<CommonParameters>]
@@ -77,10 +82,10 @@ Specifies whether to show deleted users.
7782
7883
```yaml
7984
Type: SwitchParameter
80-
Parameter Sets: ByCustomerId
85+
Parameter Sets: ByUserState
8186
Aliases:
8287

83-
Required: False
88+
Required: True
8489
Position: Named
8590
Default value: None
8691
Accept pipeline input: False

docs/help/Get-PartnerInvoiceLineItem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The billing provide for the line items.
4040
Type: BillingProvider
4141
Parameter Sets: (All)
4242
Aliases:
43-
Accepted values: All, Azure, Office, OneTime, Marketplace
43+
Accepted values: All, Azure, Marketplace, Office, OneTime
4444

4545
Required: True
4646
Position: Named

docs/help/New-PartnerAccessToken.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,37 @@ Acquires an access token from Azure Active Directory.
1717
### AccessToken
1818
```powershell
1919
New-PartnerAccessToken -AccessToken <String> -ApplicationId <String> [-Credential <PSCredential>]
20-
[-Environment <EnvironmentName>] [-RefreshToken <String>] -Scopes <String[]> [-Tenant <String>]
21-
[-UseAuthorizationCode] [<CommonParameters>]
20+
[-Environment <EnvironmentName>] -Scopes <String[]> [-Tenant <String>] [<CommonParameters>]
21+
```
22+
23+
### RefreshToken
24+
```powershell
25+
New-PartnerAccessToken [-ApplicationId <String>] [-Credential <PSCredential>] [-Environment <EnvironmentName>]
26+
[-Module <ModuleName>] -RefreshToken <String> -Scopes <String[]> [-ServicePrincipal] [-Tenant <String>]
27+
[<CommonParameters>]
2228
```
2329

2430
### ServicePrincipal
2531
```powershell
2632
New-PartnerAccessToken -ApplicationId <String> -Credential <PSCredential> [-Environment <EnvironmentName>]
27-
[-RefreshToken <String>] -Scopes <String[]> [-ServicePrincipal] -Tenant <String> [-UseAuthorizationCode]
28-
[<CommonParameters>]
33+
-Scopes <String[]> [-ServicePrincipal] -Tenant <String> [-UseAuthorizationCode] [<CommonParameters>]
2934
```
3035

3136
### ServicePrincipalCertificate
3237
```powershell
3338
New-PartnerAccessToken -ApplicationId <String> -CertificateThumbprint <String> [-Environment <EnvironmentName>]
34-
[-RefreshToken <String>] -Scopes <String[]> [-ServicePrincipal] -Tenant <String> [-UseAuthorizationCode]
35-
[<CommonParameters>]
39+
-Scopes <String[]> [-ServicePrincipal] -Tenant <String> [-UseAuthorizationCode] [<CommonParameters>]
3640
```
3741

3842
### User
3943
```powershell
40-
New-PartnerAccessToken -ApplicationId <String> [-Environment <EnvironmentName>] [-RefreshToken <String>]
41-
-Scopes <String[]> [-Tenant <String>] [-UseAuthorizationCode] [-UseDeviceAuthentication] [<CommonParameters>]
44+
New-PartnerAccessToken -ApplicationId <String> [-Environment <EnvironmentName>] -Scopes <String[]>
45+
[-Tenant <String>] [-UseAuthorizationCode] [-UseDeviceAuthentication] [<CommonParameters>]
4246
```
4347

4448
### ByModule
4549
```powershell
46-
New-PartnerAccessToken [-Environment <EnvironmentName>] -Module <ModuleName> [-RefreshToken <String>]
50+
New-PartnerAccessToken [-Environment <EnvironmentName>] -Module <ModuleName> -Scopes <String[]>
4751
[-Tenant <String>] [-UseAuthorizationCode] [<CommonParameters>]
4852
```
4953

@@ -103,6 +107,18 @@ Accept pipeline input: False
103107
Accept wildcard characters: False
104108
```
105109
110+
```yaml
111+
Type: String
112+
Parameter Sets: RefreshToken
113+
Aliases: ClientId
114+
115+
Required: False
116+
Position: Named
117+
Default value: None
118+
Accept pipeline input: False
119+
Accept wildcard characters: False
120+
```
121+
106122
### -CertificateThumbprint
107123
Certificate Hash (Thumbprint)
108124
@@ -123,7 +139,7 @@ Credentials that represents the service principal.
123139
124140
```yaml
125141
Type: PSCredential
126-
Parameter Sets: AccessToken
142+
Parameter Sets: AccessToken, RefreshToken
127143
Aliases:
128144

129145
Required: False
@@ -164,6 +180,19 @@ Accept wildcard characters: False
164180
### -Module
165181
The module that an access token is being generated.
166182
183+
```yaml
184+
Type: ModuleName
185+
Parameter Sets: RefreshToken
186+
Aliases: ModuleName
187+
Accepted values: ExchangeOnline
188+
189+
Required: False
190+
Position: Named
191+
Default value: None
192+
Accept pipeline input: False
193+
Accept wildcard characters: False
194+
```
195+
167196
```yaml
168197
Type: ModuleName
169198
Parameter Sets: ByModule
@@ -182,10 +211,10 @@ The refresh token to use during authentication.
182211
183212
```yaml
184213
Type: String
185-
Parameter Sets: (All)
214+
Parameter Sets: RefreshToken
186215
Aliases:
187216

188-
Required: False
217+
Required: True
189218
Position: Named
190219
Default value: None
191220
Accept pipeline input: False
@@ -197,7 +226,7 @@ Scopes requested to access a protected API.
197226
198227
```yaml
199228
Type: String[]
200-
Parameter Sets: AccessToken, ServicePrincipal, ServicePrincipalCertificate, User
229+
Parameter Sets: (All)
201230
Aliases:
202231

203232
Required: True
@@ -212,10 +241,10 @@ Indicates that this account authenticates by providing service principal credent
212241
213242
```yaml
214243
Type: SwitchParameter
215-
Parameter Sets: ServicePrincipal
244+
Parameter Sets: RefreshToken, ServicePrincipalCertificate
216245
Aliases:
217246

218-
Required: True
247+
Required: False
219248
Position: Named
220249
Default value: None
221250
Accept pipeline input: False
@@ -224,10 +253,10 @@ Accept wildcard characters: False
224253
225254
```yaml
226255
Type: SwitchParameter
227-
Parameter Sets: ServicePrincipalCertificate
256+
Parameter Sets: ServicePrincipal
228257
Aliases:
229258

230-
Required: False
259+
Required: True
231260
Position: Named
232261
Default value: None
233262
Accept pipeline input: False
@@ -239,7 +268,7 @@ The identifier of the Azure AD tenant.
239268
240269
```yaml
241270
Type: String
242-
Parameter Sets: AccessToken, User, ByModule
271+
Parameter Sets: AccessToken, RefreshToken, User, ByModule
243272
Aliases: Domain, TenantId
244273

245274
Required: False
@@ -266,7 +295,7 @@ Use the authorization code flow during authentication.
266295
267296
```yaml
268297
Type: SwitchParameter
269-
Parameter Sets: (All)
298+
Parameter Sets: ServicePrincipal, ServicePrincipalCertificate, User, ByModule
270299
Aliases: AuthCode
271300

272301
Required: False

src/PowerShell/Authenticators/AccessTokenAuthenticator.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
namespace Microsoft.Store.PartnerCenter.PowerShell.Authenticators
55
{
66
using System;
7-
using System.Linq;
8-
using System.Management.Automation;
97
using System.Security.Claims;
108
using System.Threading;
119
using System.Threading.Tasks;
@@ -32,16 +30,7 @@ internal class AccessTokenAuthenticator : DelegatingAuthenticator
3230
public override async Task<AuthenticationResult> AuthenticateAsync(AuthenticationParameters parameters, CancellationToken cancellationToken = default)
3331
{
3432
JsonWebToken token;
35-
string value;
36-
37-
if (parameters.Scopes.Contains($"{parameters.Environment.PartnerCenterEndpoint}/user_impersonation"))
38-
{
39-
value = parameters.Account.GetProperty(PartnerAccountPropertyType.AccessToken);
40-
}
41-
else
42-
{
43-
throw new PSInvalidOperationException("This operation is not supported when you connect using an access token. Please connect interactively or using a refresh token.");
44-
}
33+
string value = parameters.Account.GetProperty(PartnerAccountPropertyType.AccessToken);
4534

4635
token = new JsonWebToken(value);
4736

src/PowerShell/Commands/AddPartnerCustomerCartLineItem.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.Commands
99
using System.Management.Automation;
1010
using System.Text.RegularExpressions;
1111
using Extensions;
12+
using Models.Authentication;
1213
using Models.Carts;
1314
using PartnerCenter.Models.Carts;
1415
using Properties;
1516

1617
/// <summary>
1718
/// Adds a cart line item to the specified cart.
1819
/// </summary>
19-
[Cmdlet(VerbsCommon.Add, "PartnerCustomerCartLineItem", SupportsShouldProcess = true), OutputType(typeof(PSCart))]
20-
public class AddPartnerCustomerCartLineItem : PartnerCmdlet
20+
[Cmdlet(VerbsCommon.Add, "PartnerCustomerCartLineItem", SupportsShouldProcess = true)]
21+
[OutputType(typeof(PSCart))]
22+
public class AddPartnerCustomerCartLineItem : PartnerAsyncCmdlet
2123
{
2224
/// <summary>
2325
/// Gets or sets the required cart identifier.
@@ -45,24 +47,29 @@ public class AddPartnerCustomerCartLineItem : PartnerCmdlet
4547
/// </summary>
4648
public override void ExecuteCmdlet()
4749
{
48-
Cart cart;
49-
CartLineItem cartLineItem;
50-
List<CartLineItem> lineItems;
51-
52-
if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.AddPartnerCustomerCartLineItemWhatIf, CartId)))
50+
Scheduler.RunTask(async () =>
5351
{
54-
cart = Partner.Customers[CustomerId].Carts[CartId].GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
55-
lineItems = cart.LineItems.ToList();
52+
Cart cart;
53+
CartLineItem cartLineItem;
54+
List<CartLineItem> lineItems;
55+
56+
if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.AddPartnerCustomerCartLineItemWhatIf, CartId)))
57+
{
58+
IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);
59+
60+
cart = await partner.Customers[CustomerId].Carts[CartId].GetAsync(CancellationToken).ConfigureAwait(false);
61+
lineItems = cart.LineItems.ToList();
5662

57-
cartLineItem = new CartLineItem();
58-
cartLineItem.CopyFrom(LineItem);
63+
cartLineItem = new CartLineItem();
64+
cartLineItem.CopyFrom(LineItem);
5965

60-
lineItems.Add(cartLineItem);
66+
lineItems.Add(cartLineItem);
6167

62-
cart = Partner.Customers[CustomerId].Carts[CartId].PutAsync(cart).GetAwaiter().GetResult();
68+
cart = await partner.Customers[CustomerId].Carts[CartId].PutAsync(cart, CancellationToken).ConfigureAwait(false);
6369

64-
WriteObject(new PSCart(cart));
65-
}
70+
WriteObject(new PSCart(cart));
71+
}
72+
}, true);
6673
}
6774
}
6875
}

0 commit comments

Comments
 (0)