Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to patch TrustFrameworkPolicy #883

Open
greiggs opened this issue Aug 21, 2024 · 4 comments
Open

Unable to patch TrustFrameworkPolicy #883

greiggs opened this issue Aug 21, 2024 · 4 comments
Labels
Bug: metadata dependency:metadata Awaiting fix from core dependency project module type:bug A broken experience

Comments

@greiggs
Copy link

greiggs commented Aug 21, 2024

Describe the bug

I am trying to write an automated system for adding and patching TrustFramework Policies using Microsoft.Identity.Web.GraphServiceClientBeta version 3.0.1 which is using Microsoft.Graph.Beta 5.78.0-preview.

I have successfully added a policy from the code provided by: Github msgraph-beta-sdk-dotnet issue 734 but I am unable to patch as it throws the following error:

No HTTP resource was found that matches the request URI 'https://cpim.windows.net/graph/trustFramework/policies('B2C_1A_TEST_01')'.","messageDetail":"No action was found on the controller 'trustframework' that matches the request.

Expected behavior

To patch a B2C Policy using the SDK. From looking at the api it indicates it should be a Put and not a Patch but there is no appropriate RequestInformation method on the graphServiceClient.TrustFramework.Policies[policyId] object.

How to reproduce

Run the following code:

Where:

  • data: is a BinaryData object of the xml policy file.
  • graphServiceClient: is a Beta.GraphServiceClient.
  • policyId: is 'B2C_1A_TEST_01'
TrustFrameworkPolicyCollectionResponse? response = await graphServiceClient.TrustFramework.Policies.GetAsync();

TrustFrameworkPolicy? existingPolicy = response?.Value?.Where(x => x.Id == policyId).FirstOrDefault();

if (existingPolicy != null) {
  RequestInformation requestInformation = graphServiceClient.TrustFramework.Policies[policyId].ToPatchRequestInformation(existingPolicy);
  
  requestInformation.SetStreamContent(data.ToStream(), "application/xml");
  requestInformation.Headers.Add("Content-Type", "application/xml");
  
  Dictionary<string, ParsableFactory<IParsable>> errorMapping = new()
  {
      {"4XX", ODataError.CreateFromDiscriminatorValue},
      {"5XX", ODataError.CreateFromDiscriminatorValue},
  };
}

await graphServiceClient.RequestAdapter.SendNoContentAsync(requestInformation, errorMapping, cancellationToken);

SDK Version

5.78.0-preview

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@greiggs greiggs added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Aug 21, 2024
@andrueastman
Copy link
Member

Thanks for raising this @greiggs

Does this work if you do this instead when creating the request information object? According to the docs the right way to update is using a PUT at the /$value endpoint.

            RequestInformation requestInformation = graphServiceClient.TrustFramework.Policies["policyId"].Content.ToPutRequestInformation(data.ToStream());
            requestInformation.Headers.Add("Content-Type", "application/xml"); // metadata sets the content type as octet-stream

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Aug 22, 2024
@greiggs
Copy link
Author

greiggs commented Aug 22, 2024

@andrueastman Yes this worked thank you.

Can I ask if the approach (below) I am using to add is the correct way to do this or is there a simpler way as this seems overly complex? Also is there any documentation in how to use the SDK as I have had trouble trying to convert what the API requires into how the SDK works?

RequestInformation requestInformation = graphServiceClient.TrustFramework.Policies.ToPostRequestInformation(new() { Id = policyId, });

requestInformation.SetStreamContent(data.ToStream(), "application/xml");
requestInformation.Headers.Add("Content-Type", "application/xml");

Dictionary<string, ParsableFactory<IParsable>> errorMapping = new()
{
    {"4XX", ODataError.CreateFromDiscriminatorValue},
    {"5XX", ODataError.CreateFromDiscriminatorValue},
};

await graphServiceClient.RequestAdapter.SendNoContentAsync(requestInformation, errorMapping, cancellationToken);

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Aug 22, 2024
Copy link
Contributor

No description provided.

@andrueastman
Copy link
Member

Thanks for confirming this @greiggs

The Graph documentation typically should have examples on how to make calls using the SDK. See example at

https://learn.microsoft.com/en-us/graph/api/trustframeworkkeyset-get?view=graph-rest-beta&tabs=csharp

However, this API seems to be an edge case as the API metadata that is provided by the API team that is used to generate the SDK is incorrect. Specifically, it does not describe that the endpoint expects xml this makes the generation assume that the api expects json which would have a call the simply looks like this.

var result = await graphServiceClient.TrustFramework.Policies["policyId"].Content.PutAsync(data.ToStream());

To fully resolve this we probably need to

Hope this helps make things clearer.

@andrueastman andrueastman added Bug: metadata dependency:metadata Awaiting fix from core dependency project module and removed Needs: Attention 👋 labels Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: metadata dependency:metadata Awaiting fix from core dependency project module type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

2 participants