Skip to content

Commit 7d56073

Browse files
authored
Parameter -TenantId is now -Tenant with alias for -TenantId (#117)
* tenant id is now an alias of tenant, since tenant name works too, closes #99 * changelog tenant parameter
1 parent 70931e2 commit 7d56073

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The format is based on and uses the types of changes according to [Keep a Change
44

55
## [Unreleased]
66

7+
### Changed
8+
9+
- `-TenantId` parameter is now called `-Tenant`, but `-TenantId` alias is still supported #99
10+
711
## [2.4.0] - 2024-12-12
812

913
### Added

docs/help/Get-AzToken.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,67 @@ Gets a new Azure access token.
1515

1616
### NonInteractive (Default)
1717
```
18-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
18+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
1919
[-ClientId <String>] [-TimeoutSeconds <Int32>] [-CredentialPrecedence <String[]>] [-Force]
2020
[<CommonParameters>]
2121
```
2222

2323
### Cache
2424
```
25-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
25+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
2626
[-ClientId <String>] -TokenCache <String> -Username <String>
2727
[<CommonParameters>]
2828
```
2929

3030
### Interactive
3131
```
32-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
32+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
3333
[-ClientId <String>] [-TokenCache <String>] [-TimeoutSeconds <Int32>] [-Interactive] [-Force]
3434
[<CommonParameters>]
3535
```
3636

3737
### Broker
3838
```
39-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
39+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
4040
[-ClientId <String>] [-Broker] [<CommonParameters>]
4141
```
4242

4343
### DeviceCode
4444
```
45-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
45+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
4646
[-ClientId <String>] [-TokenCache <String>] [-TimeoutSeconds <Int32>] [-DeviceCode] [-Force]
4747
[<CommonParameters>]
4848
```
4949

5050
### ManagedIdentity
5151
```
52-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-TenantId <String>] [-Claim <String>]
52+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] [-Tenant <String>] [-Claim <String>]
5353
[-ClientId <String>] [-TimeoutSeconds <Int32>] [-ManagedIdentity] [-Force]
5454
[<CommonParameters>]
5555
```
5656

5757
### WorkloadIdentity
5858
```
59-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
60-
-ClientId <String> [-WorkloadIdentity] -ExternalToken <String> [-Force]
61-
[<CommonParameters>]
59+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
60+
[-WorkloadIdentity] -ExternalToken <String> [-Force] [<CommonParameters>]
6261
```
6362

6463
### ClientSecret
6564
```
66-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
67-
-ClientId <String> -ClientSecret <String> [-Force] [<CommonParameters>]
65+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
66+
-ClientSecret <String> [-Force] [<CommonParameters>]
6867
```
6968

7069
### ClientCertificate
7170
```
72-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
73-
-ClientId <String> -ClientCertificate <X509Certificate2> [-Force]
74-
[<CommonParameters>]
71+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
72+
-ClientCertificate <X509Certificate2> [-Force] [<CommonParameters>]
7573
```
7674

7775
### ClientCertificatePath
7876
```
79-
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -TenantId <String> [-Claim <String>]
80-
-ClientId <String> -ClientCertificatePath <String> [-Force]
81-
[<CommonParameters>]
77+
Get-AzToken [[-Resource] <String>] [[-Scope] <String[]>] -Tenant <String> [-Claim <String>] -ClientId <String>
78+
-ClientCertificatePath <String> [-Force] [<CommonParameters>]
8279
```
8380

8481
## DESCRIPTION
@@ -416,14 +413,13 @@ Accept pipeline input: False
416413
Accept wildcard characters: False
417414
```
418415

419-
### -TenantId
420-
421-
The id of the tenant that the token should be valid for.
416+
### -Tenant
417+
The id or name of the tenant that the token should be valid for.
422418

423419
```yaml
424420
Type: String
425421
Parameter Sets: NonInteractive, Cache, Interactive, Broker, DeviceCode, ManagedIdentity
426-
Aliases:
422+
Aliases: TenantId
427423
428424
Required: False
429425
Position: Named
@@ -435,7 +431,7 @@ Accept wildcard characters: False
435431
```yaml
436432
Type: String
437433
Parameter Sets: WorkloadIdentity, ClientSecret, ClientCertificate, ClientCertificatePath
438-
Aliases:
434+
Aliases: TenantId
439435
440436
Required: True
441437
Position: Named

source/AzAuth.PS/Cmdlets/GetAzToken.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class GetAzToken : PSLoggerCmdletBase
4747
[Parameter(ParameterSetName = "ClientCertificate", Mandatory = true)]
4848
[Parameter(ParameterSetName = "ClientCertificatePath", Mandatory = true)]
4949
[ValidateNotNullOrEmpty]
50-
public string TenantId { get; set; }
50+
[Alias("TenantId")]
51+
public string Tenant { get; set; }
5152

5253
[Parameter(ParameterSetName = "NonInteractive")]
5354
[Parameter(ParameterSetName = "Cache")]
@@ -190,17 +191,17 @@ should be
190191

191192
WriteVerbose(@$"Looking for a token from the following sources:
192193
{string.Join(Environment.NewLine, CredentialPrecedence.Select(cred => $"{cred} ({TokenManager.GetCredentialDocumentationUrl(cred)})"))}");
193-
WriteObject(TokenManager.GetTokenNonInteractive(Resource, Scope, Claim, TenantId, CredentialPrecedence, noninteractiveTimeoutSeconds, managedIdentityTimeoutSeconds, stopProcessing.Token));
194+
WriteObject(TokenManager.GetTokenNonInteractive(Resource, Scope, Claim, Tenant, CredentialPrecedence, noninteractiveTimeoutSeconds, managedIdentityTimeoutSeconds, stopProcessing.Token));
194195
}
195196
else if (ParameterSetName == "Cache")
196197
{
197198
WriteVerbose($"Getting token from token cache named \"{TokenCache}\".");
198-
WriteObject(TokenManager.GetTokenFromCache(Resource, Scope, Claim, ClientId, TenantId, TokenCache!, Username, stopProcessing.Token));
199+
WriteObject(TokenManager.GetTokenFromCache(Resource, Scope, Claim, ClientId, Tenant, TokenCache!, Username, stopProcessing.Token));
199200
}
200201
else if (Interactive.IsPresent)
201202
{
202203
WriteVerbose("Getting token interactively using the default browser.");
203-
WriteObject(TokenManager.GetTokenInteractive(Resource, Scope, Claim, ClientId, TenantId, TokenCache, TimeoutSeconds, stopProcessing.Token));
204+
WriteObject(TokenManager.GetTokenInteractive(Resource, Scope, Claim, ClientId, Tenant, TokenCache, TimeoutSeconds, stopProcessing.Token));
204205
}
205206
else if (Broker.IsPresent)
206207
{
@@ -209,7 +210,7 @@ should be
209210
{
210211
throw new PlatformNotSupportedException("The WAM broker authentication is only supported on Windows.");
211212
}
212-
WriteObject(TokenManager.GetTokenInteractiveBroker(Resource, Scope, Claim, ClientId, TenantId, TimeoutSeconds, stopProcessing.Token));
213+
WriteObject(TokenManager.GetTokenInteractiveBroker(Resource, Scope, Claim, ClientId, Tenant, TimeoutSeconds, stopProcessing.Token));
213214
}
214215
else if (DeviceCode.IsPresent)
215216
{
@@ -218,7 +219,7 @@ should be
218219
// Set up a BlockingCollection to use for logging device code message
219220
BlockingCollection<string> loggingQueue = new();
220221
// Start device code flow and save task
221-
var tokenTask = joinableTaskFactory.RunAsync(() => TokenManager.GetTokenDeviceCodeAsync(Resource, Scope, Claim, ClientId, TenantId, TokenCache, TimeoutSeconds, loggingQueue, stopProcessing.Token));
222+
var tokenTask = joinableTaskFactory.RunAsync(() => TokenManager.GetTokenDeviceCodeAsync(Resource, Scope, Claim, ClientId, Tenant, TokenCache, TimeoutSeconds, loggingQueue, stopProcessing.Token));
222223

223224
// Loop through messages and log them to warning stream (verbose is silent by default)
224225
try
@@ -241,27 +242,27 @@ should be
241242
TimeoutSeconds = 1;
242243
}
243244
WriteVerbose("Getting token using a managed identity (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.managedidentitycredential).");
244-
WriteObject(TokenManager.GetTokenManagedIdentity(Resource, Scope, Claim, ClientId, TenantId, TimeoutSeconds, stopProcessing.Token));
245+
WriteObject(TokenManager.GetTokenManagedIdentity(Resource, Scope, Claim, ClientId, Tenant, TimeoutSeconds, stopProcessing.Token));
245246
}
246247
else if (WorkloadIdentity.IsPresent)
247248
{
248249
WriteVerbose($"Getting token using workload identity federation (using client assertion) for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientassertioncredential).");
249-
WriteObject(TokenManager.GetTokenWorkloadIdentity(Resource, Scope, Claim, ClientId, TenantId, ExternalToken, stopProcessing.Token));
250+
WriteObject(TokenManager.GetTokenWorkloadIdentity(Resource, Scope, Claim, ClientId, Tenant, ExternalToken, stopProcessing.Token));
250251
}
251252
else if (ParameterSetName == "ClientSecret")
252253
{
253254
WriteVerbose($"Getting token using client secret for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientsecretcredential).");
254-
WriteObject(TokenManager.GetTokenClientSecret(Resource, Scope, Claim, ClientId, TenantId, ClientSecret, stopProcessing.Token));
255+
WriteObject(TokenManager.GetTokenClientSecret(Resource, Scope, Claim, ClientId, Tenant, ClientSecret, stopProcessing.Token));
255256
}
256257
else if (ParameterSetName == "ClientCertificate")
257258
{
258259
WriteVerbose($"Getting token using client certificate for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientcertificatecredential).");
259-
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, TenantId, ClientCertificate, stopProcessing.Token));
260+
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, Tenant, ClientCertificate, stopProcessing.Token));
260261
}
261262
else if (ParameterSetName == "ClientCertificatePath")
262263
{
263264
WriteVerbose($"Getting token using client certificate for client \"{ClientId}\" (https://learn.microsoft.com/en-us/dotnet/api/azure.identity.clientcertificatecredential).");
264-
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, TenantId, ClientCertificatePath, stopProcessing.Token));
265+
WriteObject(TokenManager.GetTokenClientCertificate(Resource, Scope, Claim, ClientId, Tenant, ClientCertificatePath, stopProcessing.Token));
265266
}
266267
else
267268
{

tests/Get-AzToken.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BeforeDiscovery {
3333
)
3434
}
3535
@{
36-
Name = 'TenantId'
36+
Name = 'Tenant'
3737
Type = 'string'
3838
ParameterSets = @(
3939
@{ Name = 'NonInteractive'; Mandatory = $false }

0 commit comments

Comments
 (0)