-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1642 from KoenZomers/AddNewPnPAzureADUserTemporar…
…yAccessPass Added cmdlet `New-PnPAzureADUserTemporaryAccessPass`
- Loading branch information
Showing
4 changed files
with
165 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
title: New-PnPAzureADUserTemporaryAccessPass | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
online version: https://pnp.github.io/powershell/cmdlets/New-PnPAzureADUserTemporaryAccessPass.html | ||
--- | ||
|
||
# New-PnPAzureADUserTemporaryAccessPass | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API : UserAuthenticationMethod.ReadWrite.All | ||
|
||
Creates a temporary access pass to authenticate with for a certain user | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
New-PnPAzureADUserTemporaryAccessPass -DisplayName <String> -Description <String> -MailNickname <String> [-Owners <String[]>] [-Members <String[]>] [-IsSecurityEnabled <SwitchParameter>] [-IsMailEnabled <SwitchParameter>] [-Force] [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
This cmdlet allows creation of a temporary access pass for a specific user to allow the user to log on once using the generated token. This can be used i.e. when the user needs to sign in to replace the multi factor authentication token. | ||
|
||
You can read more on how to enable Temporary Access Pass in Azure Active Directory in [this article](https://docs.microsoft.com/azure/active-directory/authentication/howto-authentication-temporary-access-pass). It is disabled by default on Azure Active Directory. | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
New-PnPAzureADUserTemporaryAccessPass -Identity johndoe@contoso.onmicrosoft.com | ||
``` | ||
|
||
Creates a temporary access pass for the user with the provided user principal name following the default configuration in Azure Active Directory towards the access pass its lifetime, password length and reusability which can directly be used. | ||
|
||
### EXAMPLE 2 | ||
```powershell | ||
New-PnPAzureADUserTemporaryAccessPass -Identity 72e2eb87-c124-4bd9-8e01-a447a1752058 -IsUseableOnce:$true | ||
``` | ||
|
||
Creates a temporary access pass for the user with the provided user Id following the default configuration in Azure Active Directory towards the access pass its lifetime and password length. The token will only be able to be used once and will then immediately expire and can directly be used. | ||
|
||
### EXAMPLE 3 | ||
```powershell | ||
New-PnPAzureADUserTemporaryAccessPass -Identity johndoe@contoso.onmicrosoft.com -StartDateTime (Get-Date).AddHours(2) -LifeTimeInMinutes 10 -IsUseableOnce:$true | ||
``` | ||
|
||
Creates a temporary access pass for the user with the provided user principal name which will not become valid for use until 2 hours from now has passed. It will then only be valid for 10 minutes and only can be used once to login after which it will immediately expire, regardless if there are minutes left in the `-LifeTimeInMinutes` parameter. | ||
|
||
### EXAMPLE 4 | ||
```powershell | ||
Get-PnPAzureADUser -Identity johndoe@contoso.onmicrosoft.com | New-PnPAzureADUserTemporaryAccessPass -StartDateTime (Get-Date).AddMinutes(10) -LifeTimeInMinutes 15 -IsUseableOnce:$false | ||
``` | ||
|
||
Creates a temporary access pass for the user with the provided user principal name which will not become valid for use until 10 minutes from now has passed. It will then only be valid for 15 minutes and only can be used repeatedly to login while there are minutes left in the `-LifeTimeInMinutes` parameter. | ||
|
||
## PARAMETERS | ||
|
||
### -Identity | ||
The user principal name, user Id or user instance for which to generate a temporary access pass. | ||
|
||
```yaml | ||
Type: AzureADUserPipeBind | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True | ||
Accept wildcard characters: False | ||
``` | ||
### -StartDateTime | ||
Date and time at which the access pass should become valid. If not provided, the access pass will immediately be valid. | ||
```yaml | ||
Type: DateTime | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -LifeTimeInMinutes | ||
Time in minutes counting from the moment the access pass has become active, how long it will be valid until it will expire and cannot be used anymore. IF not provided, the configured default in Azure Active Directory will be used. | ||
```yaml | ||
Type: Int32 | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -IsUseableOnce | ||
Allows defining if the access token can only be used once to log on after which it will directly expire. This takes presedence over the `-LifeTimeInMinutes` option. If not provided, the configured default in Azure Active Directory will be used. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
## RELATED LINKS | ||
|
||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
[Microsoft Graph documentation](https://docs.microsoft.com/graph/api/temporaryaccesspassauthenticationmethod-post) | ||
[Feature description](https://docs.microsoft.com/azure/active-directory/authentication/howto-authentication-temporary-access-pass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using PnP.Framework.Graph; | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Graph | ||
{ | ||
[Cmdlet(VerbsCommon.New, "PnPAzureADUserTemporaryAccessPass")] | ||
[RequiredMinimalApiPermissions("UserAuthenticationMethod.ReadWrite.All")] | ||
public class NewAzureADUserTemporaryAccessPass : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = true, ValueFromPipeline = true)] | ||
public AzureADUserPipeBind Identity; | ||
|
||
[Parameter(Mandatory = false)] | ||
public DateTime? StartDateTime; | ||
|
||
[Parameter(Mandatory = false)] | ||
public int? LifeTimeInMinutes; | ||
|
||
[Parameter(Mandatory = false)] | ||
public SwitchParameter IsUsableOnce; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var accessPass = UsersUtility.RequestTemporaryAccessPass( | ||
accessToken: AccessToken, | ||
userId: Identity.User?.Id?.ToString() ?? Identity.Upn ?? Identity.UserId, | ||
startDateTime: StartDateTime, | ||
lifeTimeInMinutes: LifeTimeInMinutes, | ||
isUsableOnce: IsUsableOnce); | ||
|
||
WriteObject(accessPass); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters