Skip to content

Commit 71cfa79

Browse files
committed
Add Graph Audience to environment cmdlets
1 parent 04e24df commit 71cfa79

File tree

7 files changed

+68
-7
lines changed

7 files changed

+68
-7
lines changed

src/Common/Commands.Common.Authentication/Commands.Common.Authentication.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,21 @@
166166
<Compile Include="Models\MemoryDataStore.cs" />
167167
<Compile Include="Models\XmlProfileSerializer.cs" />
168168
<Compile Include="Properties\AssemblyInfo.cs" />
169-
<Compile Include="Properties\Resources.Designer.cs" />
169+
<Compile Include="Properties\Resources.Designer.cs">
170+
<AutoGen>True</AutoGen>
171+
<DesignTime>True</DesignTime>
172+
<DependentUpon>Resources.resx</DependentUpon>
173+
</Compile>
170174
<Compile Include="Utilities\DictionaryExtensions.cs" />
171175
<Compile Include="Utilities\FileUtilities.cs" />
172176
<Compile Include="Utilities\JsonUtilities.cs" />
173177
<Compile Include="Utilities\XmlUtilities.cs" />
174178
</ItemGroup>
175179
<ItemGroup>
176-
<EmbeddedResource Include="Properties\Resources.resx" />
180+
<EmbeddedResource Include="Properties\Resources.resx">
181+
<Generator>PublicResXFileCodeGenerator</Generator>
182+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
183+
</EmbeddedResource>
177184
</ItemGroup>
178185
<ItemGroup>
179186
<None Include="packages.config" />

src/Common/Commands.Common.Authentication/Factories/AuthenticationFactory.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,24 @@ private AdalConfiguration GetAdalConfiguration(AzureEnvironment environment, str
287287
{
288288
throw new ArgumentNullException("environment");
289289
}
290+
290291
var adEndpoint = environment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory];
292+
if (string.IsNullOrWhiteSpace(adEndpoint))
293+
{
294+
throw new ArgumentOutOfRangeException("environment", string.Format("No Active Directory endpoint specified for environment '{0}'", environment.Name));
295+
}
296+
297+
var audience = environment.Endpoints[resourceId];
298+
if (string.IsNullOrWhiteSpace(audience))
299+
{
300+
string message = Resources.InvalidManagementTokenAudience;
301+
if (resourceId == AzureEnvironment.Endpoint.GraphEndpointResourceId)
302+
{
303+
message = Resources.InvalidGraphTokenAudience;
304+
}
305+
306+
throw new ArgumentOutOfRangeException("environment", string.Format(message, environment.Name));
307+
}
291308

292309
return new AdalConfiguration
293310
{

src/Common/Commands.Common.Authentication/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Commands.Common.Authentication/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,10 @@
300300
<data name="UnsupportedCredentialType" xml:space="preserve">
301301
<value>Certificate authentication is not supported for account type {0}.</value>
302302
</data>
303+
<data name="InvalidGraphTokenAudience" xml:space="preserve">
304+
<value>No value was specified for the token audience for the graph endpoint in environment '{0}'. Please use Set-AzureRmEnvironment -Name {0} -GraphAudience token-audience-value</value>
305+
</data>
306+
<data name="InvalidManagementTokenAudience" xml:space="preserve">
307+
<value>No value was specified for the token audience for the management endpoint in environment '{0}'. Please use Set-AzureRmEnvironment -Name {0} -ActiveDirectoryServiceEndpointResourceId token-audience-value</value>
308+
</data>
303309
</root>

src/ResourceManager/Profile/Commands.Profile.Test/EnvironmentCmdletTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public void CanCreateEnvironmentWithAllProperties()
193193
ServiceEndpoint = "ServiceEndpoint",
194194
StorageEndpoint = "StorageEndpoint",
195195
SqlDatabaseDnsSuffix = "SqlDatabaseDnsSuffix",
196-
TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix"
196+
TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix",
197+
GraphAudience = "GaraphAudience"
197198
};
198199

199200
cmdlet.InvokeBeginProcessing();
@@ -216,6 +217,7 @@ public void CanCreateEnvironmentWithAllProperties()
216217
Assert.Equal(cmdlet.StorageEndpoint, actual.StorageEndpointSuffix);
217218
Assert.Equal(cmdlet.SqlDatabaseDnsSuffix, actual.SqlDatabaseDnsSuffix);
218219
Assert.Equal( cmdlet.TrafficManagerDnsSuffix , actual.TrafficManagerDnsSuffix);
220+
Assert.Equal( cmdlet.GraphAudience , actual.GraphEndpointResourceId);
219221
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
220222
AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
221223
Assert.Equal(env.Name, cmdlet.Name);

src/ResourceManager/Profile/Commands.Profile/Environment/AddAzureRMEnvironment.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ public class AddAzureRMEnvironmentCommand : AzureRMCmdlet
9898
HelpMessage = "The default tenant for this environment.")]
9999
public string AdTenant { get; set; }
100100

101-
protected override void BeginProcessing()
101+
[Parameter(Position = 18, Mandatory = false, ValueFromPipelineByPropertyName = true,
102+
HelpMessage = "The audience for tokens authenticating with the AD Graph Endpoint.")]
103+
[Alias("GraphEndpointResourceId", "GraphResourceId")]
104+
public string GraphAudience { get; set; }
105+
106+
protected override void BeginProcessing()
102107
{
103108
// do not call begin processing there is no context needed for this cmdlet
104109
}
@@ -129,7 +134,8 @@ public override void ExecuteCmdlet()
129134
newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix] = AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix;
130135
newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix] = AzureDataLakeStoreFileSystemEndpointSuffix;
131136
newEnvironment.Endpoints[AzureEnvironment.Endpoint.AdTenant] = AdTenant;
132-
WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment));
137+
newEnvironment.Endpoints[AzureEnvironment.Endpoint.GraphEndpointResourceId] = GraphAudience;
138+
WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment));
133139
}
134140
}
135141
}

src/ResourceManager/Profile/Commands.Profile/Environment/SetAzureRMEnvironment.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ public class SetAzureRMEnvironmentCommand : AzureRMCmdlet
100100
HelpMessage = "The default tenant for this environment.")]
101101
public string AdTenant { get; set; }
102102

103-
protected override void BeginProcessing()
103+
[Parameter(Position = 18, Mandatory = false, ValueFromPipelineByPropertyName = true,
104+
HelpMessage = "The audience for tokens authenticating with the AD Graph Endpoint.")]
105+
[Alias("GraphEndpointResourceId", "GraphResourceId")]
106+
public string GraphAudience { get; set; }
107+
108+
protected override void BeginProcessing()
104109
{
105110
// do not call begin processing there is no context needed for this cmdlet
106111
}
@@ -139,7 +144,7 @@ public override void ExecuteCmdlet()
139144
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix, AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix);
140145
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix, AzureDataLakeStoreFileSystemEndpointSuffix);
141146
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AdTenant, AdTenant);
142-
147+
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.GraphEndpointResourceId, GraphAudience);
143148
profileClient.AddOrSetEnvironment(newEnvironment);
144149

145150
WriteObject((PSAzureEnvironment)newEnvironment);

0 commit comments

Comments
 (0)