diff --git a/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs b/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs index 9090fd957e..ee0b7bf41c 100644 --- a/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs +++ b/src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs @@ -453,6 +453,10 @@ internal async Task ProcessResponseAsync(HttpResponseMessage response) throw new ArgumentOutOfRangeException(nameof(OutputType)); } break; + case RestReturnType.PlainText: + responseString = await response.Content.ReadAsStringAsync(); + WriteObject(responseString); + break; case RestReturnType.OctetStream: if (OutputType == OutputType.HttpResponseMessage) WriteObject(response); diff --git a/src/Authentication/Authentication/Helpers/ContentHelper.cs b/src/Authentication/Authentication/Helpers/ContentHelper.cs index deac70d63b..76efd269b5 100644 --- a/src/Authentication/Authentication/Helpers/ContentHelper.cs +++ b/src/Authentication/Authentication/Helpers/ContentHelper.cs @@ -29,6 +29,8 @@ internal static RestReturnType CheckReturnType(this HttpResponseMessage response rt = RestReturnType.Image; else if (IsOctetStream(contentType)) rt = RestReturnType.OctetStream; + else if (IsPlainText(contentType)) + rt = RestReturnType.PlainText; return rt; } @@ -80,6 +82,8 @@ private static bool CheckIsOctetStream(string contentType) return isOctetStream; } + private static bool IsPlainText(string contentType) => contentType.Equals("text/plain", StringComparison.OrdinalIgnoreCase); + // used to split contentType arguments private static readonly char[] ContentTypeParamSeparator = { ';' }; diff --git a/src/Authentication/Authentication/Models/RestReturnType.cs b/src/Authentication/Authentication/Models/RestReturnType.cs index e55693eef1..212f5c834b 100644 --- a/src/Authentication/Authentication/Models/RestReturnType.cs +++ b/src/Authentication/Authentication/Models/RestReturnType.cs @@ -24,6 +24,10 @@ public enum RestReturnType /// /// image/* (image/jpeg, image/png) return type /// - Image = 4 + Image = 4, + /// + /// text/plain return type + /// + PlainText = 5 } } \ No newline at end of file diff --git a/src/Authentication/Authentication/test/Invoke-MgGraphRequest.Tests.ps1 b/src/Authentication/Authentication/test/Invoke-MgGraphRequest.Tests.ps1 index dfb34a661e..be63f884d3 100644 --- a/src/Authentication/Authentication/test/Invoke-MgGraphRequest.Tests.ps1 +++ b/src/Authentication/Authentication/test/Invoke-MgGraphRequest.Tests.ps1 @@ -54,6 +54,9 @@ Describe 'Invoke-MgGraphRequest Command' -skip { It 'Should not throw when -InferOutputFilePath is specified' { { Invoke-MgGraphRequest -OutputType PSObject -Uri "https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" -InferOutputFileName } | Should -Not -Throw } + It 'Should return plain text' { + { Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/applications/`$count" } | Should -BeOfType [System.String] + } } Context 'Absolute and relative URIs' {