Skip to content
21 changes: 15 additions & 6 deletions src/Authentication/Authentication/Cmdlets/InvokeGraphRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
using Microsoft.Graph.PowerShell.Authentication.Properties;
using Microsoft.PowerShell.Commands;

using Newtonsoft.Json;

using DriveNotFoundException = System.Management.Automation.DriveNotFoundException;

namespace Microsoft.Graph.PowerShell.Authentication.Cmdlets
Expand Down Expand Up @@ -552,7 +554,10 @@ private HttpResponseMessage GetResponse(HttpClient client, HttpRequestMessage re
}

/// <summary>
/// Set the request content
/// Set the request content.
/// Convert Dictionaries to Json
/// Passing a dictionary to the body object should be translated to Json.
/// Almost everything on Microsoft Graph works converts dictionaries and arrays to JSON.
/// </summary>
/// <param name="request"></param>
/// <param name="content"></param>
Expand All @@ -568,8 +573,8 @@ private long SetRequestContent(HttpRequestMessage request, IDictionary content)
{
throw new ArgumentNullException(nameof(content));
}

var body = content.FormatDictionary();
// Covert all dictionaries to Json
var body = JsonConvert.SerializeObject(content);
return SetRequestContent(request, body);
}

Expand Down Expand Up @@ -668,6 +673,8 @@ private void FillRequestStream(HttpRequestMessage request)
{
content = psBody.BaseObject;
}
// Passing a dictionary to the body object should be translated to Json.
// Almost everything on Microsoft Graph works converts dictionaries and arrays to JSON.
if (content is IDictionary dictionary && request.Method != HttpMethod.Get)
{
SetRequestContent(request, dictionary);
Expand Down Expand Up @@ -703,14 +710,15 @@ private void FillRequestStream(HttpRequestMessage request)
}

// Add the content headers
if (request.Content == null)
// Only Set Content Headers when its not a GET Request
if (request.Content == null && this.Method != GraphRequestMethod.GET)
{
request.Content = new StringContent(string.Empty);
request.Content.Headers.Clear();
}

foreach (var entry in GraphRequestSession.ContentHeaders.Where(header =>
!string.IsNullOrWhiteSpace(header.Value)))
!string.IsNullOrWhiteSpace(header.Value)))
{
if (SkipHeaderValidation)
{
Expand All @@ -724,7 +732,8 @@ private void FillRequestStream(HttpRequestMessage request)
}
catch (FormatException ex)
{
var outerEx = new ValidationMetadataException(Resources.ContentTypeExceptionErrorMessage, ex);
var outerEx =
new ValidationMetadataException(Resources.ContentTypeExceptionErrorMessage, ex);
var er = new ErrorRecord(outerEx, Errors.InvokeGraphContentTypeException,
ErrorCategory.InvalidArgument, ContentType);
ThrowTerminatingError(er);
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Authentication/Helpers/ContentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static bool CheckIsText(string contentType)
|| CheckIsJson(contentType);

// Further content type analysis is available on Windows
if (Platform.IsWindows && !isText)
if (OperatingSystem.IsWindows() && !isText)
{
// Media types registered with Windows as having a perceived type of text, are text
using (var contentTypeKey = Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type\" + contentType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal string PlatformName
{
get
{
if (Platform.IsWindows)
if (OperatingSystem.IsWindows())
{
// only generate the windows user agent once
if (_windowsUserAgent == null)
Expand All @@ -69,11 +69,11 @@ internal string PlatformName

return _windowsUserAgent;
}
else if (Platform.IsMacOS)
else if (OperatingSystem.IsMacOS())
{
return "Macintosh";
}
else if (Platform.IsLinux)
else if (OperatingSystem.IsLinux())
{
return "Linux";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="5.6.0" />
<PackageReference Include="Microsoft.IdentityModel.Logging" Version="5.6.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0" />
<PackageReference Include="Microsoft.PowerShell.Commands.Utility" Version="6.0.4" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft
#
# Generated on: 5/4/2020
# Generated on: 8/12/2020
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = './Microsoft.Graph.Authentication.psm1'

# Version number of this module.
ModuleVersion = '0.9.0'
ModuleVersion = '0.9.1'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -72,7 +72,8 @@ FormatsToProcess = './Microsoft.Graph.Authentication.format.ps1xml'
FunctionsToExport = @()

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = 'Connect-Graph', 'Disconnect-Graph', 'Get-MgContext', 'Get-MgProfile', 'Select-MgProfile', 'Invoke-GraphRequest'
CmdletsToExport = 'Connect-Graph', 'Disconnect-Graph', 'Get-MgContext', 'Get-MgProfile',
'Select-MgProfile', 'Invoke-GraphRequest'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 6/30/2020
# Generated on: 8/11/2020
#

@{
Expand All @@ -12,13 +12,13 @@
RootModule = './Microsoft.Graph.Identity.TermsOfUse.psm1'

# Version number of this module.
ModuleVersion = '0.5.1'
ModuleVersion = '0.9.0'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'

# ID used to uniquely identify this module
GUID = 'e2dba82b-3bad-46a7-ac83-ecfe5e873824'
GUID = 'ffdc7898-a776-425d-ad61-339458b87aa4'

# Author of this module
Author = 'Microsoft Corporation'
Expand Down Expand Up @@ -51,7 +51,7 @@ DotNetFrameworkVersion = '4.7.2'
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '0.7.0'; })
RequiredModules = @(@{ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '0.9.0'; })

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = './bin/Microsoft.Graph.Identity.TermsOfUse.private.dll'
Expand All @@ -70,11 +70,15 @@ FormatsToProcess = './Microsoft.Graph.Identity.TermsOfUse.format.ps1xml'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Get-MgAgreement', 'Get-MgAgreementAcceptance', 'Get-MgAgreementFile',
'Get-MgUserAgreementAcceptance', 'New-MgAgreement',
'Get-MgAgreementFileLocalization', 'Get-MgUserAgreementAcceptance',
'Get-MgUserAgreementAcceptanceByRef', 'New-MgAgreement',
'New-MgAgreementAcceptance', 'New-MgAgreementFile',
'Remove-MgAgreement', 'Remove-MgAgreementAcceptance',
'Update-MgAgreement', 'Update-MgAgreementAcceptance',
'Update-MgAgreementFile'
'New-MgAgreementFileLocalization',
'New-MgUserAgreementAcceptanceByRef', 'Remove-MgAgreement',
'Remove-MgAgreementAcceptance', 'Remove-MgAgreementFile',
'Remove-MgAgreementFileLocalization', 'Update-MgAgreement',
'Update-MgAgreementAcceptance', 'Update-MgAgreementFile',
'Update-MgAgreementFileLocalization'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
Expand Down
14 changes: 14 additions & 0 deletions src/Identity.TermsOfUse/Identity.TermsOfUse/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ title: $(service-name)
subject-prefix: ''

```

### Directives

> see https://github.com/Azure/autorest/blob/master/docs/powershell/directives.md

``` yaml
directive:
# Rename cmdlets
- where:
subject: AgreementFile
variant: Get1|GetViaIdentity1|Delete1|DeleteViaIdentity1|Update1|UpdateExpanded1|UpdateViaIdentity1|UpdateViaIdentityExpanded1
remove: true
```

### Versioning

``` yaml
Expand Down