Skip to content

Commit

Permalink
Parameter -TenantId is now -Tenant with alias for -TenantId (#117)
Browse files Browse the repository at this point in the history
* tenant id is now an alias of tenant, since tenant name works too, closes #99

* changelog tenant parameter
  • Loading branch information
PalmEmanuel authored Dec 18, 2024
1 parent 70931e2 commit 7d56073
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on and uses the types of changes according to [Keep a Change

## [Unreleased]

### Changed

- `-TenantId` parameter is now called `-Tenant`, but `-TenantId` alias is still supported #99

## [2.4.0] - 2024-12-12

### Added
Expand Down
40 changes: 18 additions & 22 deletions docs/help/Get-AzToken.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,67 @@ Gets a new Azure access token.

### NonInteractive (Default)
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
[-ClientId <String>] [-TimeoutSeconds <Int32>] [-CredentialPrecedence <String[]>] [-Force]
[<CommonParameters>]
```

### Cache
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
[-ClientId <String>] -TokenCache <String> -Username <String>
[<CommonParameters>]
```

### Interactive
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
[-ClientId <String>] [-TokenCache <String>] [-TimeoutSeconds <Int32>] [-Interactive] [-Force]
[<CommonParameters>]
```

### Broker
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
[-ClientId <String>] [-Broker] [<CommonParameters>]
```

### DeviceCode
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
[-ClientId <String>] [-TokenCache <String>] [-TimeoutSeconds <Int32>] [-DeviceCode] [-Force]
[<CommonParameters>]
```

### ManagedIdentity
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
[-ClientId <String>] [-TimeoutSeconds <Int32>] [-ManagedIdentity] [-Force]
[<CommonParameters>]
```

### WorkloadIdentity
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
-ClientId <String> [-WorkloadIdentity] -ExternalToken <String> [-Force]
[<CommonParameters>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
[-WorkloadIdentity] -ExternalToken <String> [-Force] [<CommonParameters>]
```

### ClientSecret
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
-ClientId <String> -ClientSecret <String> [-Force] [<CommonParameters>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
-ClientSecret <String> [-Force] [<CommonParameters>]
```

### ClientCertificate
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
-ClientId <String> -ClientCertificate <X509Certificate2> [-Force]
[<CommonParameters>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
-ClientCertificate <X509Certificate2> [-Force] [<CommonParameters>]
```

### ClientCertificatePath
```
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
-ClientId <String> -ClientCertificatePath <String> [-Force]
[<CommonParameters>]
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
-ClientCertificatePath <String> [-Force] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -416,14 +413,13 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -TenantId

The id of the tenant that the token should be valid for.
### -Tenant
The id or name of the tenant that the token should be valid for.

```yaml
Type: String
Parameter Sets: NonInteractive, Cache, Interactive, Broker, DeviceCode, ManagedIdentity
Aliases:
Aliases: TenantId
Required: False
Position: Named
Expand All @@ -435,7 +431,7 @@ Accept wildcard characters: False
```yaml
Type: String
Parameter Sets: WorkloadIdentity, ClientSecret, ClientCertificate, ClientCertificatePath
Aliases:
Aliases: TenantId
Required: True
Position: Named
Expand Down
23 changes: 12 additions & 11 deletions source/AzAuth.PS/Cmdlets/GetAzToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class GetAzToken : PSLoggerCmdletBase
[Parameter(ParameterSetName = "ClientCertificate", Mandatory = true)]
[Parameter(ParameterSetName = "ClientCertificatePath", Mandatory = true)]
[ValidateNotNullOrEmpty]
public string TenantId { get; set; }
[Alias("TenantId")]
public string Tenant { get; set; }

[Parameter(ParameterSetName = "NonInteractive")]
[Parameter(ParameterSetName = "Cache")]
Expand Down Expand Up @@ -190,17 +191,17 @@ should be

WriteVerbose(@$"Looking for a token from the following sources:
{string.Join(Environment.NewLine, CredentialPrecedence.Select(cred => $"{cred} ({TokenManager.GetCredentialDocumentationUrl(cred)})"))}");
WriteObject(TokenManager.GetTokenNonInteractive(Resource, Scope, Claim, TenantId, CredentialPrecedence, noninteractiveTimeoutSeconds, managedIdentityTimeoutSeconds, stopProcessing.Token));
WriteObject(TokenManager.GetTokenNonInteractive(Resource, Scope, Claim, Tenant, CredentialPrecedence, noninteractiveTimeoutSeconds, managedIdentityTimeoutSeconds, stopProcessing.Token));
}
else if (ParameterSetName == "Cache")
{
WriteVerbose($"Getting token from token cache named \"{TokenCache}\".");
WriteObject(TokenManager.GetTokenFromCache(Resource, Scope, Claim, ClientId, TenantId, TokenCache!, Username, stopProcessing.Token));
WriteObject(TokenManager.GetTokenFromCache(Resource, Scope, Claim, ClientId, Tenant, TokenCache!, Username, stopProcessing.Token));
}
else if (Interactive.IsPresent)
{
WriteVerbose("Getting token interactively using the default browser.");
WriteObject(TokenManager.GetTokenInteractive(Resource, Scope, Claim, ClientId, TenantId, TokenCache, TimeoutSeconds, stopProcessing.Token));
WriteObject(TokenManager.GetTokenInteractive(Resource, Scope, Claim, ClientId, Tenant, TokenCache, TimeoutSeconds, stopProcessing.Token));
}
else if (Broker.IsPresent)
{
Expand All @@ -209,7 +210,7 @@ should be
{
throw new PlatformNotSupportedException("The WAM broker authentication is only supported on Windows.");
}
WriteObject(TokenManager.GetTokenInteractiveBroker(Resource, Scope, Claim, ClientId, TenantId, TimeoutSeconds, stopProcessing.Token));
WriteObject(TokenManager.GetTokenInteractiveBroker(Resource, Scope, Claim, ClientId, Tenant, TimeoutSeconds, stopProcessing.Token));
}
else if (DeviceCode.IsPresent)
{
Expand All @@ -218,7 +219,7 @@ should be
// Set up a BlockingCollection to use for logging device code message
BlockingCollection<string> loggingQueue = new();
// Start device code flow and save task
var tokenTask = joinableTaskFactory.RunAsync(() => TokenManager.GetTokenDeviceCodeAsync(Resource, Scope, Claim, ClientId, TenantId, TokenCache, TimeoutSeconds, loggingQueue, stopProcessing.Token));
var tokenTask = joinableTaskFactory.RunAsync(() => TokenManager.GetTokenDeviceCodeAsync(Resource, Scope, Claim, ClientId, Tenant, TokenCache, TimeoutSeconds, loggingQueue, stopProcessing.Token));

// Loop through messages and log them to warning stream (verbose is silent by default)
try
Expand All @@ -241,27 +242,27 @@ should be
TimeoutSeconds = 1;
}
WriteVerbose("Getting token using a managed identity (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.managedidentitycredential).");
WriteObject(TokenManager.GetTokenManagedIdentity(Resource, Scope, Claim, ClientId, TenantId, TimeoutSeconds, stopProcessing.Token));
WriteObject(TokenManager.GetTokenManagedIdentity(Resource, Scope, Claim, ClientId, Tenant, TimeoutSeconds, stopProcessing.Token));
}
else if (WorkloadIdentity.IsPresent)
{
WriteVerbose($"Getting token using workload identity federation (using client assertion) for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientassertioncredential).");
WriteObject(TokenManager.GetTokenWorkloadIdentity(Resource, Scope, Claim, ClientId, TenantId, ExternalToken, stopProcessing.Token));
WriteObject(TokenManager.GetTokenWorkloadIdentity(Resource, Scope, Claim, ClientId, Tenant, ExternalToken, stopProcessing.Token));
}
else if (ParameterSetName == "ClientSecret")
{
WriteVerbose($"Getting token using client secret for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientsecretcredential).");
WriteObject(TokenManager.GetTokenClientSecret(Resource, Scope, Claim, ClientId, TenantId, ClientSecret, stopProcessing.Token));
WriteObject(TokenManager.GetTokenClientSecret(Resource, Scope, Claim, ClientId, Tenant, ClientSecret, stopProcessing.Token));
}
else if (ParameterSetName == "ClientCertificate")
{
WriteVerbose($"Getting token using client certificate for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientcertificatecredential).");
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, TenantId, ClientCertificate, stopProcessing.Token));
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, Tenant, ClientCertificate, stopProcessing.Token));
}
else if (ParameterSetName == "ClientCertificatePath")
{
WriteVerbose($"Getting token using client certificate for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientcertificatecredential).");
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, TenantId, ClientCertificatePath, stopProcessing.Token));
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, Tenant, ClientCertificatePath, stopProcessing.Token));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Get-AzToken.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BeforeDiscovery {
)
}
@{
Name = 'TenantId'
Name = 'Tenant'
Type = 'string'
ParameterSets = @(
@{ Name = 'NonInteractive'; Mandatory = $false }
Expand Down

0 comments on commit 7d56073

Please sign in to comment.