Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
49 changes: 5 additions & 44 deletions src/Applications/wrapper/v1.0/Cmdlets/AddMgApplicationKey.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Management.Automation;
using System.Net.Http;
using Microsoft.Graph.PowerShell.Authentication.Helpers;
using Microsoft.Graph.Wrapper.Runtime;
using Microsoft.Graph.PowerShell.Applications.Client;
using Microsoft.Graph.PowerShell.Applications.Client.Models;
using Microsoft.Kiota.Abstractions;
Expand All @@ -17,7 +17,7 @@ namespace Microsoft.Graph.PowerShell.Applications
[GraphRoute("POST", "/applications/{application-id}/addKey")]
[Cmdlet(VerbsCommon.Add, "MgApplicationKey", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType(typeof(Microsoft.Graph.PowerShell.Applications.Client.Models.KeyCredential))]
public class AddMgApplicationKeyCommand : PSCmdlet
public class AddMgApplicationKeyCommand : GraphClientCmdlet
{
[Parameter(Mandatory = true, Position = 0)]
public string ApplicationId { get; set; } = string.Empty;
Expand All @@ -34,13 +34,7 @@ public class AddMgApplicationKeyCommand : PSCmdlet



[Parameter(Mandatory = false,
HelpMessage = "Additional HTTP request headers to send, keyed by header name.")]
public System.Collections.IDictionary? Headers { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Bearer access token. Omit if you have already run Connect-MgGraph.")]
public string? AccessToken { get; set; }

protected override void ProcessRecord()
{
Expand All @@ -57,36 +51,7 @@ protected override void ProcessRecord()
if (this.IsParameterBound(nameof(PasswordCredential)))
body.PasswordCredential = PasswordCredential;

// ── Choose HttpClient + auth provider ─────────────────────────────
HttpClient httpClient;
IAuthenticationProvider authProvider;

if (this.IsParameterBound(nameof(AccessToken)))
{
httpClient = new HttpClient();
authProvider = new StaticBearerTokenAuthenticationProvider(AccessToken!);
}
else
{
WriteVerbose("No -AccessToken supplied, using the active Connect-MgGraph session.");
try
{
httpClient = HttpHelpers.GetGraphHttpClient();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(
new InvalidOperationException(
"No active Graph session. Run Connect-MgGraph first, or supply -AccessToken.", ex),
"NoGraphSession",
ErrorCategory.AuthenticationError,
null));
return;
}
authProvider = new AnonymousAuthenticationProvider();
}

var requestAdapter = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
var requestAdapter = GetRequestAdapter();
var client = new ApiClient(requestAdapter);

Microsoft.Graph.PowerShell.Applications.Client.Models.KeyCredential? result;
Expand All @@ -95,16 +60,12 @@ protected override void ProcessRecord()
result = client.Applications[ApplicationId].AddKey.PostAsync(body, requestConfiguration =>
{

if (this.IsParameterBound(nameof(Headers)))
{
foreach (System.Collections.DictionaryEntry entry in Headers!)
requestConfiguration.Headers.Add(entry.Key.ToString()!, entry.Value?.ToString() ?? string.Empty);
}
AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(ex, "GraphRequestFailed", ErrorCategory.InvalidOperation, ApplicationId));
ThrowGraphRequestFailed(ex, ApplicationId);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Management.Automation;
using System.Net.Http;
using Microsoft.Graph.PowerShell.Authentication.Helpers;
using Microsoft.Graph.Wrapper.Runtime;
using Microsoft.Graph.PowerShell.Applications.Client;
using Microsoft.Graph.PowerShell.Applications.Client.Models;
using Microsoft.Kiota.Abstractions;
Expand All @@ -17,7 +17,7 @@ namespace Microsoft.Graph.PowerShell.Applications
[GraphRoute("POST", "/applications/{application-id}/addPassword")]
[Cmdlet(VerbsCommon.Add, "MgApplicationPassword", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType(typeof(Microsoft.Graph.PowerShell.Applications.Client.Models.PasswordCredential))]
public class AddMgApplicationPasswordCommand : PSCmdlet
public class AddMgApplicationPasswordCommand : GraphClientCmdlet
{
[Parameter(Mandatory = true, Position = 0)]
public string ApplicationId { get; set; } = string.Empty;
Expand All @@ -29,13 +29,7 @@ public class AddMgApplicationPasswordCommand : PSCmdlet



[Parameter(Mandatory = false,
HelpMessage = "Additional HTTP request headers to send, keyed by header name.")]
public System.Collections.IDictionary? Headers { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Bearer access token. Omit if you have already run Connect-MgGraph.")]
public string? AccessToken { get; set; }

protected override void ProcessRecord()
{
Expand All @@ -47,36 +41,7 @@ protected override void ProcessRecord()
if (this.IsParameterBound(nameof(PasswordCredential)))
body.PasswordCredential = PasswordCredential;

// ── Choose HttpClient + auth provider ─────────────────────────────
HttpClient httpClient;
IAuthenticationProvider authProvider;

if (this.IsParameterBound(nameof(AccessToken)))
{
httpClient = new HttpClient();
authProvider = new StaticBearerTokenAuthenticationProvider(AccessToken!);
}
else
{
WriteVerbose("No -AccessToken supplied, using the active Connect-MgGraph session.");
try
{
httpClient = HttpHelpers.GetGraphHttpClient();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(
new InvalidOperationException(
"No active Graph session. Run Connect-MgGraph first, or supply -AccessToken.", ex),
"NoGraphSession",
ErrorCategory.AuthenticationError,
null));
return;
}
authProvider = new AnonymousAuthenticationProvider();
}

var requestAdapter = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
var requestAdapter = GetRequestAdapter();
var client = new ApiClient(requestAdapter);

Microsoft.Graph.PowerShell.Applications.Client.Models.PasswordCredential? result;
Expand All @@ -85,16 +50,12 @@ protected override void ProcessRecord()
result = client.Applications[ApplicationId].AddPassword.PostAsync(body, requestConfiguration =>
{

if (this.IsParameterBound(nameof(Headers)))
{
foreach (System.Collections.DictionaryEntry entry in Headers!)
requestConfiguration.Headers.Add(entry.Key.ToString()!, entry.Value?.ToString() ?? string.Empty);
}
AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(ex, "GraphRequestFailed", ErrorCategory.InvalidOperation, ApplicationId));
ThrowGraphRequestFailed(ex, ApplicationId);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Management.Automation;
using System.Net.Http;
using Microsoft.Graph.PowerShell.Authentication.Helpers;
using Microsoft.Graph.Wrapper.Runtime;
using Microsoft.Graph.PowerShell.Applications.Client;
using Microsoft.Graph.PowerShell.Applications.Client.Models;
using Microsoft.Kiota.Abstractions;
Expand All @@ -17,7 +17,7 @@ namespace Microsoft.Graph.PowerShell.Applications
[GraphRoute("POST", "/servicePrincipals/{servicePrincipal-id}/addKey")]
[Cmdlet(VerbsCommon.Add, "MgServicePrincipalKey", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType(typeof(Microsoft.Graph.PowerShell.Applications.Client.Models.KeyCredential))]
public class AddMgServicePrincipalKeyCommand : PSCmdlet
public class AddMgServicePrincipalKeyCommand : GraphClientCmdlet
{
[Parameter(Mandatory = true, Position = 0)]
public string ServicePrincipalId { get; set; } = string.Empty;
Expand All @@ -34,13 +34,7 @@ public class AddMgServicePrincipalKeyCommand : PSCmdlet



[Parameter(Mandatory = false,
HelpMessage = "Additional HTTP request headers to send, keyed by header name.")]
public System.Collections.IDictionary? Headers { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Bearer access token. Omit if you have already run Connect-MgGraph.")]
public string? AccessToken { get; set; }

protected override void ProcessRecord()
{
Expand All @@ -57,36 +51,7 @@ protected override void ProcessRecord()
if (this.IsParameterBound(nameof(PasswordCredential)))
body.PasswordCredential = PasswordCredential;

// ── Choose HttpClient + auth provider ─────────────────────────────
HttpClient httpClient;
IAuthenticationProvider authProvider;

if (this.IsParameterBound(nameof(AccessToken)))
{
httpClient = new HttpClient();
authProvider = new StaticBearerTokenAuthenticationProvider(AccessToken!);
}
else
{
WriteVerbose("No -AccessToken supplied, using the active Connect-MgGraph session.");
try
{
httpClient = HttpHelpers.GetGraphHttpClient();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(
new InvalidOperationException(
"No active Graph session. Run Connect-MgGraph first, or supply -AccessToken.", ex),
"NoGraphSession",
ErrorCategory.AuthenticationError,
null));
return;
}
authProvider = new AnonymousAuthenticationProvider();
}

var requestAdapter = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
var requestAdapter = GetRequestAdapter();
var client = new ApiClient(requestAdapter);

Microsoft.Graph.PowerShell.Applications.Client.Models.KeyCredential? result;
Expand All @@ -95,16 +60,12 @@ protected override void ProcessRecord()
result = client.ServicePrincipals[ServicePrincipalId].AddKey.PostAsync(body, requestConfiguration =>
{

if (this.IsParameterBound(nameof(Headers)))
{
foreach (System.Collections.DictionaryEntry entry in Headers!)
requestConfiguration.Headers.Add(entry.Key.ToString()!, entry.Value?.ToString() ?? string.Empty);
}
AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(ex, "GraphRequestFailed", ErrorCategory.InvalidOperation, ServicePrincipalId));
ThrowGraphRequestFailed(ex, ServicePrincipalId);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Management.Automation;
using System.Net.Http;
using Microsoft.Graph.PowerShell.Authentication.Helpers;
using Microsoft.Graph.Wrapper.Runtime;
using Microsoft.Graph.PowerShell.Applications.Client;
using Microsoft.Graph.PowerShell.Applications.Client.Models;
using Microsoft.Kiota.Abstractions;
Expand All @@ -17,7 +17,7 @@ namespace Microsoft.Graph.PowerShell.Applications
[GraphRoute("POST", "/servicePrincipals/{servicePrincipal-id}/addPassword")]
[Cmdlet(VerbsCommon.Add, "MgServicePrincipalPassword", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType(typeof(Microsoft.Graph.PowerShell.Applications.Client.Models.PasswordCredential))]
public class AddMgServicePrincipalPasswordCommand : PSCmdlet
public class AddMgServicePrincipalPasswordCommand : GraphClientCmdlet
{
[Parameter(Mandatory = true, Position = 0)]
public string ServicePrincipalId { get; set; } = string.Empty;
Expand All @@ -29,13 +29,7 @@ public class AddMgServicePrincipalPasswordCommand : PSCmdlet



[Parameter(Mandatory = false,
HelpMessage = "Additional HTTP request headers to send, keyed by header name.")]
public System.Collections.IDictionary? Headers { get; set; }

[Parameter(Mandatory = false,
HelpMessage = "Bearer access token. Omit if you have already run Connect-MgGraph.")]
public string? AccessToken { get; set; }

protected override void ProcessRecord()
{
Expand All @@ -47,36 +41,7 @@ protected override void ProcessRecord()
if (this.IsParameterBound(nameof(PasswordCredential)))
body.PasswordCredential = PasswordCredential;

// ── Choose HttpClient + auth provider ─────────────────────────────
HttpClient httpClient;
IAuthenticationProvider authProvider;

if (this.IsParameterBound(nameof(AccessToken)))
{
httpClient = new HttpClient();
authProvider = new StaticBearerTokenAuthenticationProvider(AccessToken!);
}
else
{
WriteVerbose("No -AccessToken supplied, using the active Connect-MgGraph session.");
try
{
httpClient = HttpHelpers.GetGraphHttpClient();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(
new InvalidOperationException(
"No active Graph session. Run Connect-MgGraph first, or supply -AccessToken.", ex),
"NoGraphSession",
ErrorCategory.AuthenticationError,
null));
return;
}
authProvider = new AnonymousAuthenticationProvider();
}

var requestAdapter = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
var requestAdapter = GetRequestAdapter();
var client = new ApiClient(requestAdapter);

Microsoft.Graph.PowerShell.Applications.Client.Models.PasswordCredential? result;
Expand All @@ -85,16 +50,12 @@ protected override void ProcessRecord()
result = client.ServicePrincipals[ServicePrincipalId].AddPassword.PostAsync(body, requestConfiguration =>
{

if (this.IsParameterBound(nameof(Headers)))
{
foreach (System.Collections.DictionaryEntry entry in Headers!)
requestConfiguration.Headers.Add(entry.Key.ToString()!, entry.Value?.ToString() ?? string.Empty);
}
AddRequestHeaders(requestConfiguration.Headers);
}).GetAwaiter().GetResult();
}
catch (Exception ex)
{
ThrowTerminatingError(new ErrorRecord(ex, "GraphRequestFailed", ErrorCategory.InvalidOperation, ServicePrincipalId));
ThrowGraphRequestFailed(ex, ServicePrincipalId);
return;
}

Expand Down
Loading
Loading