You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
extend Invoke-MgGraphRequest to handle PUT body / Unauthorized during build #483
I need to PUT a body with this operation https://graph.microsoft.com/beta/identityGovernance/entitlementManagement/accessPackageAssignmentPolicies/{id} and get a 400 Bad Request although the same body works on the respective Graph API operation.
If I interpret InvokeMgGraphRequest.cs correctly, the body is just not added to the request stream for a PUT method operation.
I wanted to extend the CmdLet myself but already struggle with .\tools\GenerateAuthenticationModule.ps1 -Build
which gives me an authentication error
WARNING: System.Collections.Hashtable
WARNING: 1.2.0
WARNING: Valid
WARNING: 1.2.0
WARNING: 1.2.0
Updated the .csproj.
Building 'Authentication' module...
Creating isolated process...
Cleaning build folders...
Compiling module...
C:\Program Files\dotnet\sdk\3.1.302\NuGet.targets(128,5): error : Failed to retrieve information about 'NETStandard.Library' from remote source 'https://pkgs.dev.azure.com/microsoftgraph/0985d294-5762-4bc2-a565-161ef349ca3e/_packaging/b395d603-5c77-4af9-a495-1e3cdbb49e1e/nuget/v2/FindPackagesById()?id='NETStandard.Library'&semVerLevel=2.0.0'. [C:\Users\kai\src\msgraph-sdk-powershell\src\Authentication\Authentication\Microsoft.Graph.Authentication.csproj]
C:\Program Files\dotnet\sdk\3.1.302\NuGet.targets(128,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\Users\kai\src\msgraph-sdk-powershell\src\Authentication\Authentication\Microsoft.Graph.Authentication.csproj]
Write-Error: C:\Users\kai\src\msgraph-sdk-powershell\src\Authentication\Authentication\build-module.ps1:47
Line |
47 | Write-Error 'Compilation failed.'
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Compilation failed.
Kai Walter (@KaiWalter) We have fixed the issue you noted. The bad request was caused by Invoke-GraphRequest sending the wrong Content-Type header text/plain instead of application/json for PUT requests when -ContentType parameter is not set.
A fix will be released with the next version.
In the mean while a workaround would be to specify the -ContentType explicitly. Invoke-MgGraphRequest -Uri $uri -Method Put -Body $body -ContentType application/json
To fix the unauthorized issue during build, remove the following lines from Nuget.config. They point to our internal build feed, we will correct this as well in the next build.
Activity
KaiWalter commentedon Dec 4, 2020
currently I use this workaround
instead of
georgend commentedon Dec 10, 2020
Kai Walter (@KaiWalter) We have fixed the issue you noted. The bad request was caused by
Invoke-GraphRequestsending the wrongContent-Typeheadertext/plaininstead ofapplication/jsonfor PUT requests when-ContentTypeparameter is not set.A fix will be released with the next version.
In the mean while a workaround would be to specify the
-ContentTypeexplicitly.Invoke-MgGraphRequest -Uri $uri -Method Put -Body $body -ContentType application/jsonTo fix the unauthorized issue during build, remove the following lines from Nuget.config. They point to our internal build feed, we will correct this as well in the next build.
msgraph-sdk-powershell/Nuget.config
Lines 4 to 6 in 437e8bf
KaiWalter commentedon Dec 11, 2020
thanks finsharp - adding
-ContentType "application/json"worked - I will try nuget feed nextKaiWalter commentedon Dec 12, 2020
removing lines from
Nuget.configworked