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

Commit c51d13f

Browse files
author
Isaiah Williams
authored
Adding new user features (#193)
1 parent a2975f3 commit c51d13f

13 files changed

+109
-62
lines changed

docs/help/Get-PartnerUser.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gets a list of users from the partner tenant
1515
## SYNTAX
1616

1717
```powershell
18-
Get-PartnerUser [<CommonParameters>]
18+
Get-PartnerUser [-UserId <String>] [-UserPrincipalName <String>] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
@@ -32,6 +32,36 @@ Gets a list of users from the partner tenant
3232

3333
## PARAMETERS
3434

35+
### -UserId
36+
The identifier for the user.
37+
38+
```yaml
39+
Type: String
40+
Parameter Sets: (All)
41+
Aliases:
42+
43+
Required: False
44+
Position: Named
45+
Default value: None
46+
Accept pipeline input: False
47+
Accept wildcard characters: False
48+
```
49+
50+
### -UserPrincipalName
51+
The user principal name for the user.
52+
53+
```yaml
54+
Type: String
55+
Parameter Sets: (All)
56+
Aliases: UPN
57+
58+
Required: False
59+
Position: Named
60+
Default value: None
61+
Accept pipeline input: False
62+
Accept wildcard characters: False
63+
```
64+
3565
### CommonParameters
3666
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
3767

docs/help/Get-PartnerUserSignInActivity.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Get-PartnerUserSignInActivity [-EndDate <DateTime>] [-StartDate <DateTime>] [-Us
2020
```
2121

2222
## DESCRIPTION
23-
Gets the sign activities for the specified user.
23+
Gets the sign-in activities for the specified user.
2424

2525
## EXAMPLES
2626

@@ -29,23 +29,23 @@ Gets the sign activities for the specified user.
2929
PS C:\> Get-PartnerUserSignInActivity -UserId '3dd89389-b34c-4f5a-975d-516df5694d7e'
3030
```
3131

32-
Gets the sign activities for the specified user.
32+
Gets the sign-in activities for the specified user.
3333

3434
### Example 2
3535
```powershell
36-
PS C:\> Get-PartnerUserSignInActivity -EndDate (Get-Date) -StartDate (Get-Date).AddDays(-7) -UserId '3dd89389-b34c-4f5a-975d-516df5694d7e'
36+
PS C:\> Get-PartnerUserSignInActivity -StartDate (Get-Date).AddDays(-7) -UserId '3dd89389-b34c-4f5a-975d-516df5694d7e'
3737
```
3838

39-
Gets the sign activities from the past seven days for the specified user.
39+
Gets the sign-in activities from the past seven days for the specified user.
4040

4141
### Example 3
4242
```powershell
4343
PS C:\> $users = Get-PartnerUser
44-
PS C:\> $activities = $users.ForEach({Get-PartnerUserSignInActivity -EndDate (Get-Date) -StartDate (Get-Date).AddDays(-7) -UserId $_.Id})
44+
PS C:\> $activities = $users.ForEach({Get-PartnerUserSignInActivity -StartDate (Get-Date).AddDays(-7) -UserId $_.Id})
4545
PS C:\> $activities | ? {$_.AuthenticationDetails | ? {$_.Succeeded -eq $true}}
4646
```
4747

48-
Gets the sign-activities from the past seven days that have successfully authenticated.
48+
Gets the sign-in activities from the past seven days that have successfully authenticated.
4949

5050
### Example 4
5151
```powershell
@@ -58,9 +58,18 @@ Gets the sign-in activities from the past seven days where the resource being ac
5858

5959
### Example 5
6060
```powershell
61+
PS C:\> $users = Get-PartnerUser
62+
PS C:\> $activities = $users.ForEach({Get-PartnerUserSignInActivity -StartDate (Get-Date).AddDays(-7) -UserId $_.Id})
63+
PS C:\> $activities | ? {$_.AuthenticationDetails | ? {$_.Succeeded -eq $true}} | ? {$_.MfaDetail -eq $null}
64+
```
65+
66+
Gets the sign-in activities from the past seven days that have successfully authenticated, but have not utilized multi-factor authentication.
67+
68+
### Example 6
69+
```powershell
6170
PS C:> $users = Get-PartnerUser
6271
PS C:> $activities = $users.ForEach({Get-PartnerUserSignInActivity -EndDate (Get-Date) -StartDate (Get-Date).AddDays(-7) -UserId $_.Id})
63-
PS C:> $activities | ? {$_.AuthenticationDetails | ? {$_.Succeeded -eq $true}} | ? {$_.MfaDetail | ? {$_.AuthMethod -eq $null}} | ? {$_.ResourceId -eq 'fa3d9a0c-3fb0-42cc-9193-47c7ecd2edbd'}
72+
PS C:> $activities | ? {$_.AuthenticationDetails | ? {$_.Succeeded -eq $true}} | ? {$_.MfaDetail -eq $null} | ? {$_.ResourceId -eq 'fa3d9a0c-3fb0-42cc-9193-47c7ecd2edbd'}
6473
```
6574

6675
Gets the sign-in activities from the past seven days where the resource being accessed was the Partner Center API and the sign-in activity was not challenged for multi-factor authentication.

src/PowerShell/Authenticators/InteractiveUserAuthenticator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override async Task<AuthenticationResult> AuthenticateAsync(Authenticatio
5151
}
5252
catch (Exception ex)
5353
{
54-
promptAction($"Port {port} is taken with exception '{ex.Message}'; trying to connect to the next port.");
54+
Console.WriteLine($"Port {port} is taken with exception '{ex.Message}'; trying to connect to the next port.");
5555
listener?.Stop();
5656
}
5757
}
@@ -60,7 +60,7 @@ public override async Task<AuthenticationResult> AuthenticateAsync(Authenticatio
6060

6161
if (app is IConfidentialClientApplication)
6262
{
63-
ICustomWebUi customWebUi = new DefaultOsBrowserWebUi(interactiveParameters.Message, promptAction);
63+
ICustomWebUi customWebUi = new DefaultOsBrowserWebUi(interactiveParameters.Message);
6464

6565
Uri authCodeUrl = await customWebUi.AcquireAuthorizationCodeAsync(
6666
await app.AsConfidentialClient().GetAuthorizationRequestUrl(parameters.Scopes).ExecuteAsync(cancellationToken).ConfigureAwait(false),
@@ -76,7 +76,7 @@ await app.AsConfidentialClient().GetAuthorizationRequestUrl(parameters.Scopes).E
7676
else
7777
{
7878
authResult = await app.AsPublicClient().AcquireTokenInteractive(parameters.Scopes)
79-
.WithCustomWebUi(new DefaultOsBrowserWebUi(interactiveParameters.Message, promptAction))
79+
.WithCustomWebUi(new DefaultOsBrowserWebUi(interactiveParameters.Message))
8080
.WithPrompt(Prompt.ForceLogin)
8181
.ExecuteAsync(cancellationToken).ConfigureAwait(false);
8282
}

src/PowerShell/Commands/ConnectPartnerCenter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ protected override void ProcessRecord()
239239
new[] { account.GetProperty(PartnerAccountPropertyType.Scope) },
240240
Message,
241241
WriteWarning,
242+
WriteDebug,
242243
CancellationToken);
243244

244245
PartnerSession.Instance.Context = new PartnerContext

src/PowerShell/Commands/GetPartnerCustomer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public override void ExecuteCmdlet()
7272
FieldFilterOperation.StartsWith,
7373
Domain))).ConfigureAwait(false).GetAwaiter().GetResult();
7474
}
75-
else
75+
else
7676
{
7777
seekCustomers = Partner.Customers.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
7878
}

src/PowerShell/Commands/GetPartnerUser.cs

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,51 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.Commands
88
using Graph;
99
using Models.Authentication;
1010

11+
/// <summary>
12+
/// Command that gets partner level user accounts.
13+
/// </summary>
1114
[Cmdlet(VerbsCommon.Get, "PartnerUser"), OutputType(typeof(User))]
1215
public class GetPartnerUser : PartnerCmdlet
1316
{
17+
/// <summary>
18+
/// Gets or sets the user identifier.
19+
/// </summary>
20+
[Parameter(HelpMessage = "The identifier for the user.", Mandatory = false)]
21+
public string UserId { get; set; }
22+
23+
/// <summary>
24+
/// Gets or sets the user principal name for the user.
25+
/// </summary>
26+
[Parameter(HelpMessage = "The user principal name for the user.", Mandatory = false)]
27+
[Alias("UPN")]
28+
public string UserPrincipalName { get; set; }
29+
1430
/// <summary>
1531
/// Executes the operations associated with the cmdlet.
1632
/// </summary>
1733
public override void ExecuteCmdlet()
1834
{
1935
IGraphServiceClient client = PartnerSession.Instance.ClientFactory.CreateGraphServiceClient();
20-
IGraphServiceUsersCollectionPage data = client.Users.Request().GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
21-
List<User> users = new List<User>();
2236

23-
users.AddRange(data.CurrentPage);
24-
25-
while (data.NextPageRequest != null)
37+
if (string.IsNullOrEmpty(UserId) && string.IsNullOrEmpty(UserPrincipalName))
2638
{
27-
data = data.NextPageRequest.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
28-
users.AddRange(data.CurrentPage);
39+
IGraphServiceUsersCollectionPage data = client.Users.Request().GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
40+
List<User> users = new List<User>(data.CurrentPage);
41+
42+
while (data.NextPageRequest != null)
43+
{
44+
data = data.NextPageRequest.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
45+
users.AddRange(data.CurrentPage);
46+
}
47+
48+
WriteObject(users, true);
2949
}
50+
else
51+
{
52+
User user = client.Users[string.IsNullOrEmpty(UserPrincipalName) ? UserId : UserPrincipalName].Request().GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
3053

31-
WriteObject(users, true);
54+
WriteObject(user);
55+
}
3256
}
3357
}
3458
}

src/PowerShell/Commands/NewPartnerAccessToken.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ protected override void ProcessRecord()
173173
Scopes,
174174
Message,
175175
WriteWarning,
176+
WriteDebug,
176177
CancellationToken);
177178

178179
byte[] cacheData = SharedTokenCacheClientFactory.GetTokenCache(ApplicationId).SerializeMsalV3();

src/PowerShell/Commands/TestPartnerSecurityRequirement.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected override void ProcessRecord()
7070
new[] { $"{environment.PartnerCenterEndpoint}/user_impersonation" },
7171
Message,
7272
WriteWarning,
73+
WriteDebug,
7374
CancellationToken);
7475

7576

src/PowerShell/Factories/AuthenticationFactory.cs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,32 @@ internal class AuthenticationFactory : IAuthenticationFactory
1919
{
2020
internal IAuthenticatorBuilder Builder => new DefaultAuthenticatorBuilder();
2121

22-
public AuthenticationResult Authenticate(PartnerAccount account, PartnerEnvironment environment, IEnumerable<string> scopes, string message = null, Action<string> promptAction = null, CancellationToken cancellationToken = default)
22+
public AuthenticationResult Authenticate(PartnerAccount account, PartnerEnvironment environment, IEnumerable<string> scopes, string message = null, Action<string> promptAction = null, Action<string> debugAction = null, CancellationToken cancellationToken = default)
2323
{
2424
AuthenticationResult authResult = null;
2525
IAuthenticator processAuthenticator = Builder.Authenticator;
26-
int retries = 5;
2726

28-
while (retries-- > 0)
27+
while (processAuthenticator != null && processAuthenticator.TryAuthenticate(GetAuthenticationParameters(account, environment, scopes, message), out Task<AuthenticationResult> result, promptAction, cancellationToken))
2928
{
30-
try
29+
authResult = result.ConfigureAwait(true).GetAwaiter().GetResult();
30+
31+
if (authResult != null)
3132
{
32-
while (processAuthenticator != null && processAuthenticator.TryAuthenticate(GetAuthenticationParameters(account, environment, scopes, message), out Task<AuthenticationResult> result, promptAction, cancellationToken))
33+
if (authResult.Account?.HomeAccountId != null)
3334
{
34-
authResult = result.ConfigureAwait(true).GetAwaiter().GetResult();
35-
36-
if (authResult != null)
37-
{
38-
if (authResult.Account?.HomeAccountId != null)
39-
{
40-
account.Identifier = authResult.Account.HomeAccountId.Identifier;
41-
account.ObjectId = authResult.Account.HomeAccountId.ObjectId;
42-
}
43-
44-
if (account.Tenant.Equals("common", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(authResult.TenantId))
45-
{
46-
account.Tenant = authResult.TenantId;
47-
}
48-
49-
break;
50-
}
35+
account.Identifier = authResult.Account.HomeAccountId.Identifier;
36+
account.ObjectId = authResult.Account.HomeAccountId.ObjectId;
37+
}
5138

52-
processAuthenticator = processAuthenticator.Next;
39+
if (account.Tenant.Equals("common", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrEmpty(authResult.TenantId))
40+
{
41+
account.Tenant = authResult.TenantId;
5342
}
54-
}
55-
catch (InvalidOperationException)
56-
{
57-
continue;
43+
44+
break;
5845
}
5946

60-
break;
47+
processAuthenticator = processAuthenticator.Next;
6148
}
6249

6350
return authResult ?? null;

src/PowerShell/Factories/IAuthenticationFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public interface IAuthenticationFactory
1818
/// Acquires the security token from the authority.
1919
/// </summary>
2020
/// <returns>The result from the authentication request.</returns>
21-
AuthenticationResult Authenticate(PartnerAccount account, PartnerEnvironment environment, IEnumerable<string> scopes, string message = null, Action<string> promptAction = null, CancellationToken cancellationToken = default);
21+
AuthenticationResult Authenticate(PartnerAccount account, PartnerEnvironment environment, IEnumerable<string> scopes, string message = null, Action<string> promptAction = null, Action<string> debugAction = null, CancellationToken cancellationToken = default);
2222
}
2323
}

0 commit comments

Comments
 (0)