Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update IdentifierUris of ADApp and DisplayName of ADServicePrincipal #14952

Merged
merged 9 commits into from
May 12, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Management.Automation;
Expand All @@ -40,19 +39,19 @@ public class NewAzureADApplicationCommand : ActiveDirectoryBaseCmdlet
[ValidateNotNullOrEmpty]
public string DisplayName { get; set; }

[CmdletParameterBreakingChange("IdentifierUris", ChangeDescription = "The value will be considered valid only if it exists as a verified domain in a tenant.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithoutCredential,
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithoutCredential,
HelpMessage = "The URIs that identify the application.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithPasswordPlain,
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithPasswordPlain,
HelpMessage = "The URIs that identify the application.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithPasswordCredential,
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithPasswordCredential,
HelpMessage = "The URIs that identify the application.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithKeyPlain,
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithKeyPlain,
HelpMessage = "The URIs that identify the application.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithKeyCredential,
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithKeyCredential,
HelpMessage = "The URIs that identify the application.")]
[ValidateNotNullOrEmpty]
public string[] IdentifierUris { get; set; }
[Alias("IdentifierUris")]
public string[] IdentifierUri { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationWithoutCredential,
HelpMessage = "The URL to the application’s homepage.")]
Expand Down Expand Up @@ -140,7 +139,7 @@ public override void ExecuteCmdlet()
{
DisplayName = DisplayName,
HomePage = HomePage,
IdentifierUris = IdentifierUris,
IdentifierUris = (IdentifierUri == null) ? new string[] { } : IdentifierUri,
ReplyUrls = ReplyUrls,
AvailableToOtherTenants = AvailableToOtherTenants
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
using Microsoft.Azure.Commands.Resources.Models;
using Microsoft.Azure.Commands.Resources.Models.Authorization;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Management.Automation;
using System.Security;
using System.Threading;
using System.Web;
using ProjectResources = Microsoft.Azure.Commands.Resources.Properties.Resources;

namespace Microsoft.Azure.Commands.ActiveDirectory
Expand All @@ -48,7 +46,6 @@ public class NewAzureADServicePrincipalCommand : ActiveDirectoryBaseCmdlet
[Parameter(Mandatory = false, ParameterSetName = SimpleParameterSet, HelpMessage = "The application id for which service principal is created.")]
public Guid ApplicationId { get; set; }

[CmdletParameterBreakingChange("DisplayName", ChangeDescription = "DisplayName is used as the IdentifierUri of created application. The value will be considered valid only if it exists as a verified domain in a tenant.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.DisplayNameWithoutCredential,
HelpMessage = "The display name for the application.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.DisplayNameWithPasswordPlain,
Expand All @@ -59,8 +56,7 @@ public class NewAzureADServicePrincipalCommand : ActiveDirectoryBaseCmdlet
HelpMessage = "The display name for the application.")]
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.DisplayNameWithKeyCredential,
HelpMessage = "The display name for the application.")]
[Parameter(Mandatory = false, ParameterSetName = SimpleParameterSet, HelpMessage = "The display name for the application. If a display name is not provided, " +
"this value will default to 'azure-powershell-MM-dd-yyyy-HH-mm-ss', where the suffix is the time of application creation.")]
[Parameter(Mandatory = false, ParameterSetName = SimpleParameterSet, HelpMessage = "The display name for the service principal is derived from the IdentifierUris of created application.")]
[ValidateNotNullOrEmpty]
public string DisplayName { get; set; }

Expand Down Expand Up @@ -196,15 +192,17 @@ public override void ExecuteCmdlet()

if (ApplicationId == Guid.Empty)
{
string uri = "http://" + DisplayName.Trim().Replace(' ', '_');


// Create an application and get the applicationId
CreatePSApplicationParameters appParameters = new CreatePSApplicationParameters
CreatePSApplicationParameters appParameters = new CreatePSApplicationParameters();

if(this.IsParameterBound(c => c.DisplayName) && !string.IsNullOrEmpty(DisplayName))
{
DisplayName = DisplayName,
IdentifierUris = new[] { uri },
HomePage = uri
};
string uri = "http://" + HttpUtility.UrlEncode(DisplayName.Trim());
appParameters.IdentifierUris = new string[] { };
appParameters.DisplayName = DisplayName;
}

if (this.IsParameterBound(c => c.PasswordCredential))
{
Expand Down Expand Up @@ -271,8 +269,6 @@ private void CreateSimpleServicePrincipal()
WriteVerbose(string.Format("No display name provided - using the default display name of '{0}'", DisplayName));
}

var identifierUri = "http://" + DisplayName;

bool printPassword = false;
bool printUseExistingSecret = true;

Expand All @@ -286,8 +282,7 @@ private void CreateSimpleServicePrincipal()
CreatePSApplicationParameters appParameters = new CreatePSApplicationParameters
{
DisplayName = DisplayName,
IdentifierUris = new[] { identifierUri },
HomePage = identifierUri,
HomePage = "http://" + HttpUtility.UrlEncode(DisplayName.Trim()),
PasswordCredentials = new PSADPasswordCredential[]
{
new PSADPasswordCredential()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Graph.RBAC.Models;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Management.Automation;
Expand Down Expand Up @@ -57,7 +56,6 @@ public class UpdateAzureADApplicationCommand : ActiveDirectoryBaseCmdlet
[ValidateNotNullOrEmpty]
public string HomePage { get; set; }

[CmdletParameterBreakingChange("IdentifierUri", ChangeDescription = "The value will be considered valid only if it exists as a verified domain in a tenant.")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationObjectIdWithUpdateParams,
HelpMessage = "The URIs that identify the application.")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ApplicationIdWithUpdateParams,
Expand Down Expand Up @@ -102,7 +100,7 @@ public override void ExecuteCmdlet()
{
DisplayName = DisplayName,
Homepage = HomePage,
IdentifierUris = IdentifierUri,
IdentifierUris = (IdentifierUri == null) ? new string[] { } : IdentifierUri,
ReplyUrls = ReplyUrl,
AvailableToOtherTenants = this.IsParameterBound(c => c.AvailableToOtherTenants) ? AvailableToOtherTenants : (bool?)null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
using Microsoft.Azure.Graph.RBAC.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;

namespace Microsoft.Azure.Commands.ActiveDirectory
{
Expand Down Expand Up @@ -48,7 +47,6 @@ public class UpdateAzureADServicePrincipalCommand : ActiveDirectoryBaseCmdlet
[ValidateNotNullOrEmpty]
public PSADServicePrincipal InputObject { get; set; }

[CmdletParameterBreakingChange("DisplayName", ChangeDescription = "DisplayName is used as the IdentifierUris of created application. The value will be considered valid only if it exists as a verified domain in a tenant.")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.SpObjectIdWithDisplayName, HelpMessage = "The display name for the service principal.")]
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.SPNWithDisplayName, HelpMessage = "The display name for the service principal.")]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet.InputObjectWithDisplayName, HelpMessage = "The display name for the service principal.")]
Expand All @@ -58,7 +56,6 @@ public class UpdateAzureADServicePrincipalCommand : ActiveDirectoryBaseCmdlet
[Parameter(Mandatory = false, HelpMessage = "The homepage for the service principal.")]
public string Homepage { get; set; }

[CmdletParameterBreakingChange("IdentifierUri", ChangeDescription = "The value will be considered valid only if it exists as a verified domain in a tenant.")]
[Parameter(Mandatory = false, HelpMessage = "The identifier URI(s) for the service principal.")]
public string[] IdentifierUri { get; set; }

Expand Down Expand Up @@ -107,7 +104,7 @@ public override void ExecuteCmdlet()
{
DisplayName = DisplayName,
Homepage = Homepage,
IdentifierUris = IdentifierUri,
IdentifierUris = (IdentifierUri == null) ? new string[] { } : IdentifierUri,
KeyCredentials = KeyCredential,
PasswordCredentials = PasswordCredential
};
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
-->

## Upcoming Release
* Changed `-IdentifierUris` in `New-AzADApplication` to optional parameter
* Removed default DisplayName of ADServicePrincipal when it is not specified
* Updated SDK to 3.13.1-preview to use GA TemplateSpecs API version
* Added `AdditionalProperties` to PSADUser and PSADGroup [#14568]
* Supported `CustomKeyIdentifier` in `New-AzADAppCredential` and `Get-AzADAppCredential` [#11457], [#13723]
Expand Down
16 changes: 8 additions & 8 deletions src/Resources/Resources/help/New-AzADApplication.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ Creates a new azure active directory application.

### ApplicationWithoutCredentialParameterSet (Default)
```
New-AzADApplication -DisplayName <String> -IdentifierUris <String[]> [-HomePage <String>]
New-AzADApplication -DisplayName <String> [-IdentifierUri <String[]>] [-HomePage <String>]
[-ReplyUrls <String[]>] [-AvailableToOtherTenants <Boolean>] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
```

### ApplicationWithPasswordPlainParameterSet
```
New-AzADApplication -DisplayName <String> -IdentifierUris <String[]> [-HomePage <String>]
New-AzADApplication -DisplayName <String> [-IdentifierUri <String[]>] [-HomePage <String>]
[-ReplyUrls <String[]>] [-AvailableToOtherTenants <Boolean>] -Password <SecureString> [-StartDate <DateTime>]
[-EndDate <DateTime>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ApplicationWithPasswordCredentialParameterSet
```
New-AzADApplication -DisplayName <String> -IdentifierUris <String[]> [-HomePage <String>]
New-AzADApplication -DisplayName <String> [-IdentifierUri <String[]>] [-HomePage <String>]
[-ReplyUrls <String[]>] [-AvailableToOtherTenants <Boolean>] -PasswordCredentials <PSADPasswordCredential[]>
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ApplicationWithKeyPlainParameterSet
```
New-AzADApplication -DisplayName <String> -IdentifierUris <String[]> [-HomePage <String>]
New-AzADApplication -DisplayName <String> [-IdentifierUri <String[]>] [-HomePage <String>]
[-ReplyUrls <String[]>] [-AvailableToOtherTenants <Boolean>] -CertValue <String> [-StartDate <DateTime>]
[-EndDate <DateTime>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ApplicationWithKeyCredentialParameterSet
```
New-AzADApplication -DisplayName <String> -IdentifierUris <String[]> [-HomePage <String>]
New-AzADApplication -DisplayName <String> [-IdentifierUri <String[]>] [-HomePage <String>]
[-ReplyUrls <String[]>] [-AvailableToOtherTenants <Boolean>] -KeyCredentials <PSADKeyCredential[]>
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```
Expand Down Expand Up @@ -172,15 +172,15 @@ Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

### -IdentifierUris
### -IdentifierUri
The URIs that identify the application.

```yaml
Type: System.String[]
Parameter Sets: (All)
Aliases:
Aliases: IdentifierUris

Required: True
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Expand Down
Loading