Code Monkey home page Code Monkey logo

mipsdk-file-cpp-basic's Introduction

page_type languages products description urlFragment
sample
cpp
python
m365
office-365
This sample application illustrates using the MIP File API to list labels, apply a label, then read the label. All SDK actions are implemented in action.cpp.
MipSDK-File-Cpp-Basic

MipSDK-File-Cpp-Basic

This sample illustrates basic SDK functionality where it:

  • Obtains the list of labels for the user
  • Prompts to input one of the label IDs
  • Prompts for a file path of a file to label
  • Applies the label
  • Reads the label from the document and displays metadata

Summary

This sample application illustrates using the MIP File API to list labels, apply a label, then read the label. All SDK actions are implemented in action.cpp.

Getting Started

Prerequisites

  • Visual Studio 2022 or later with Visual C++ development features installed
  • Python 3+ installed and in the system path

Sample Setup

In Visual Studio 2022:

  1. Right-click the project and select Manage NuGet Packages
  2. On the Browse tab, search for Microsoft.InformationProtection.File
  3. Select the package and click Install

Create an Azure AD App Registration

Authentication against the Azure AD tenant requires creating a native application registration. The client ID created in this step is used in a later step to generate an OAuth2 token.

Skip this step if you've already created a registration for previous sample. You may continue to use that client ID.

  1. Go to https://portal.azure.com and log in as a global admin.

    Your tenant may permit standard users to register applications. If you aren't a global admin, you can attempt these steps, but may need to work with a tenant administrator to have an application registered or be granted access to register applications.

  2. Select Azure Active Directory, then App Registrations on the left side menu.
  3. Select New registration
  4. For name, enter MipSdk-Sample-Apps
  5. Under Supported account types set Accounts in this organizational directory only

    Optionally, set this to Accounts in any organizational directory.

  6. Select Register

The Application registration screen should now be displaying your new application.

Add API Permissions

  1. Select API Permissions
  2. Select Add a permission
  3. Select Azure Rights Management Services
  4. Select Delegated permissions
  5. Check user_impersonation and select Add permissions at the bottom of the screen.
  6. Select Add a permission
  7. Select APIs my organization uses
  8. In the search box, type Microsoft Information Protection Sync Service then select the service.
  9. Select Delegated permissions
  10. Check UnifiedPolicy.User.Read then select Add permissions
  11. In the API permissions menu, select Grant admin consent for and confirm.

Set Redirect URI

  1. Select Authentication.
  2. Select Add a platform.
  3. Select Mobile and desktop applications
  4. Select the default native client redirect URI, which should look similar to https://login.microsoftonline.com/common/oauth2/nativeclient.
  5. Under Advanced settings set Treat as a public client to yes.

    This is required only for the MIP SDK sample apps using MSAL for Python.

  6. Select configure and be sure to save and changes if required.

Update Client ID, Username, and Password

  1. Open up main.cpp.
  2. Replace YOUR CLIENT ID HERE with the client ID copied from the AAD App Registration.
  3. Find the tokens for YOUR USERNAME HERE and YOUR PASSWORD HERE and insert test user credentials.

DO NOT hard code a production username and password.

Run the Sample

Press F5 to run the sample. The console application will start and after a brief moment displays the labels available for the user.

  • Copy a label ID to the clipboard.
  • Paste the label in to the input prompt.
  • Next, the app asks for a path to a file. Enter the path to an Office document or PDF file.
  • Finally, the app will display the name of the applied label.
  • Attempt to open the file in a viewer that supports labeling or protection (Office or Adobe Reader)

Resources

mipsdk-file-cpp-basic's People

Contributors

grdinin avatar microsoftopensource avatar msftgits avatar tommoser avatar v-hearya avatar zhang-yangchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mipsdk-file-cpp-basic's Issues

BadInputError while committing the modified label to new output file

When I am trying to commit modified label to the new file, the app crashes and goes unresponsive .. Below are the debugger logs for the same:

'MIP.exe' (Win32): Loaded 'C:\Windows\SysWOW64\userenv.dll'.
Exception thrown at 0x76E10592 in MIP.exe: Microsoft C++ exception: CommonUtil::CHResultExceptionImpl at memory location 0x04F9F488.
Exception thrown at 0x76E10592 in MIP.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
'MIP.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gpapi.dll'.
'MIP.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ncryptsslp.dll'.
The thread 0x51e0 has exited with code 0 (0x0).
The thread 0x513c has exited with code 0 (0x0).
The thread 0x11b0 has exited with code 0 (0x0).
The thread 0x2308 has exited with code 0 (0x0).
The thread 0x37d4 has exited with code 0 (0x0).
Exception thrown at 0x76E10592 in MIP.exe: Microsoft C++ exception: mipns::BadInputError at memory location 0x010FEED0.
Exception thrown at 0x76E10592 in MIP.exe: Microsoft C++ exception: mipns::BadInputError at memory location 0x010FDBA0.
Exception thrown at 0x76E10592 in MIP.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
Unhandled exception at 0x76E10592 in MIP.exe: Microsoft C++ exception: mipns::BadInputError at memory location 0x010FDBA0

mip::AccessDeniedError while trying to commit changes to the output file

Unhandled exception at 0x00007FFF688AA388 in MipSdk-FileApi-Cpp-Sample-Basic.exe: Microsoft C++ exception: mip::AccessDeniedError at memory location 0x00000080FDFFE500.

KernelBase.dll!00007fff688aa388()	Unknown
msvcp140d.dll!00007fff3d0710fb()	Unknown
msvcp140d.dll!00007fff3d0713fc()	Unknown
msvcp140d.dll!00007fff3d0851a3()	Unknown
msvcp140d.dll!00007fff3d08526c()	Unknown
msvcp140d.dll!00007fff3d0851ea()	Unknown
MipSdk-FileApi-Cpp-Sample-Basic.exe!std::_Associated_state<bool>::_Get_value(bool _Get_only_once) Line 315	C++
MipSdk-FileApi-Cpp-Sample-Basic.exe!std::_State_manager<bool>::_Get_value() Line 920	C++
MipSdk-FileApi-Cpp-Sample-Basic.exe!std::future<bool>::get() Line 1045

MipSdk-FileApi-Cpp-Sample-Basic.exe!sample::file::Action::CommitChanges(const std::shared_ptrmip::FileHandler & fileHandler, const std::basic_string<char,std::char_traits,std::allocator > & outputFile) Line 214 C++
MipSdk-FileApi-Cpp-Sample-Basic.exe!sample::file::Action::SetLabel(const std::basic_string<char,std::char_traits,std::allocator > & filepath, const std::basic_string<char,std::char_traits,std::allocator > & outputfile, const std::basic_string<char,std::char_traits,std::allocator > & labelId) Line 191 C++
MipSdk-FileApi-Cpp-Sample-Basic.exe!main() Line 90 C++
[External Code]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.