I am trying to apply Office sensitivity labels to a file in a .NET web application. I based myself mainly on this demo project: https://github.com/Azure-Samples/MipSDK-File-Razor-Sample
My application registration has the correct permissions as specified in that project. I can fetch the active labels, but when I try to apply the label to a filestream, I get the following error:
Microsoft.InformationProtection.Exceptions.ServiceDisabledException: 'Calling principal is forbidden to perform the operation, CorrelationId=616b22f2-cbf0-4636-b959-a90adc68456f, CorrelationId.Description=FileHandler, HttpRequest.Id=d8d6666c-4b94-4ee1-8b4b-d7b1645acadf, ServiceDisabledError.Extent=User'
I can't figure out what the root cause of this error is, if it's something I can change in my code or if there are still permissions missing from my app registration.
This is the relevant function:
public MemoryStream ApplyMipLabel(Stream inputStream, string labelId)
{
IFileEngine engine = GetEngine(_defaultEngineId);
// Create a handler with a hardcoded file name, using the input stream.
IFileHandler handler = engine.CreateFileHandlerAsync(inputStream, "HrData.xlsx", false).GetAwaiter().GetResult();
LabelingOptions options = new()
{
AssignmentMethod = AssignmentMethod.Standard
};
// Set the label on the handler.
var label = engine.GetLabelById(labelId);
handler.SetLabel(label, options, new ProtectionSettings());
MemoryStream outputStream = new MemoryStream();
// Commit the change and write to the outputStream.
handler.CommitAsync(outputStream).GetAwaiter().GetResult(); // ERROR HAPPENS HERE
return outputStream;
}