page_type | languages | products | description | urlFragment | ||||
---|---|---|---|---|---|---|---|---|
sample |
|
|
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 |
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
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.
- Visual Studio 2022 or later with Visual C++ development features installed
- Python 3+ installed and in the system path
In Visual Studio 2022:
- Right-click the project and select Manage NuGet Packages
- On the Browse tab, search for Microsoft.InformationProtection.File
- Select the package and click Install
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.
- 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.
- Select Azure Active Directory, then App Registrations on the left side menu.
- Select New registration
- For name, enter MipSdk-Sample-Apps
- Under Supported account types set Accounts in this organizational directory only
Optionally, set this to Accounts in any organizational directory.
- Select Register
The Application registration screen should now be displaying your new application.
- Select API Permissions
- Select Add a permission
- Select Azure Rights Management Services
- Select Delegated permissions
- Check user_impersonation and select Add permissions at the bottom of the screen.
- Select Add a permission
- Select APIs my organization uses
- In the search box, type Microsoft Information Protection Sync Service then select the service.
- Select Delegated permissions
- Check UnifiedPolicy.User.Read then select Add permissions
- In the API permissions menu, select Grant admin consent for and confirm.
- Select Authentication.
- Select Add a platform.
- Select Mobile and desktop applications
- Select the default native client redirect URI, which should look similar to https://login.microsoftonline.com/common/oauth2/nativeclient.
- 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.
- Select configure and be sure to save and changes if required.
- Open up main.cpp.
- Replace YOUR CLIENT ID HERE with the client ID copied from the AAD App Registration.
- 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.
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)