다음을 통해 공유


Quickstart: List Protection Templates (C++)

This Quickstart shows you how to use the MIP Protection SDK, to protection templates available to the user.

필수 조건

아직 완료하지 않은 경우 계속하기 전에 다음 필수 조건을 완료해야 합니다.

Add logic to list the protection templates

Add logic to list protection templates available to a user, using the Protection engine object.

  1. Open the Visual Studio solution you created in the previous "Quickstart - Client application initialization - Protection SDK (C++)" article.

  2. 솔루션 탐색기를 사용하여 메서드 구현 main() 이 포함된 프로젝트에서 .cpp 파일을 엽니다. 기본 이름은 프로젝트 생성 시 지정한 이름을 포함한 프로젝트와 동일합니다.

  3. using 다음 지시문을 using mip::ProtectionEngine;파일 위쪽에 추가합니다.

    using std::endl;
    
  4. 본문 끝부분에서 마지막 main() 블록의 닫는 중괄호 } 아래, 이전 빠른 시작에서 중단한 위치인 catch 위쪽에 다음 코드를 삽입합니다.

     // List protection templates
     const shared_ptr<ProtectionEngineObserver> engineObserver = std::make_shared<ProtectionEngineObserver>();
     // Create a context to pass to 'ProtectionEngine::GetTemplateListAsync'. That context will be forwarded to the
     // corresponding ProtectionEngine::Observer methods. In this case, we use promises/futures as a simple way to detect
     // the async operation completes synchronously.
     auto loadPromise = std::make_shared<std::promise<vector<shared_ptr<mip::TemplateDescriptor>>>>();
     std::future<vector<shared_ptr<mip::TemplateDescriptor>>> loadFuture = loadPromise->get_future();
     engine->GetTemplatesAsync(engineObserver, loadPromise);
     auto templates = loadFuture.get();
    
     cout << "*** Template List: " << endl;
    
     for (const auto& protectionTemplate : templates) {
         cout << "Name: " << protectionTemplate->GetName() << " : " << protectionTemplate->GetId() << endl;
     }
    
    

액세스 토큰을 생성하는 PowerShell 스크립트 만들기

PowerShell 스크립트를 사용하여 AuthDelegateImpl::AcquireOAuth2Token 구현에서 SDK가 요청하는 액세스 토큰을 생성합니다. 스크립트는 이전에 설치한 ADAL.PS 모듈의 "MIP SDK 설치 및 구성"에서 cmdlet을 사용합니다 Get-ADALToken .

  1. PowerShell 스크립트 파일(.ps1 확장명)을 만들고 다음 스크립트를 복사하여 파일에 붙여넣습니다.

    • $authority$resourceUrl 다음 섹션에서 나중에 업데이트됩니다.
    • $appId$redirectUri를 Microsoft Entra 앱 등록에서 지정한 값과 일치하도록 업데이트하십시오.
    $authority = '<authority-url>'                   # Specified when SDK calls AcquireOAuth2Token()
    $resourceUrl = '<resource-url>'                  # Specified when SDK calls AcquireOAuth2Token()
    $appId = '<app-ID>'                              # App ID of the Azure AD app registration
    $redirectUri = '<redirect-uri>'                  # Redirect URI of the Azure AD app registration
    $response = Get-ADALToken -Resource $resourceUrl -ClientId $appId -RedirectUri $redirectUri -Authority $authority -PromptBehavior:RefreshSession
    $response.AccessToken | clip                     # Copy the access token text to the clipboard
    
  2. 나중에 클라이언트 애플리케이션에서 요청할 때 실행할 수 있도록 스크립트 파일을 저장합니다.

애플리케이션 빌드 및 테스트

마지막으로 클라이언트 애플리케이션을 빌드하고 테스트합니다.

  1. Use Ctrl+Shift+b (Build Solution) to build your client application. 빌드 오류가 없는 경우 F5(디버깅 시작)를 사용하여 애플리케이션을 실행합니다.

  2. 프로젝트가 성공적으로 빌드되고 실행되면 애플리케이션은 SDK가 메서드를 호출할 때마다 액세스 토큰을 묻는 메시지를 표시합니다 AcquireOAuth2Token() . You can reuse a previously generated token, if prompted multiple times and the requested values are the same:

  3. 프롬프트에 대한 액세스 토큰을 생성하려면 PowerShell 스크립트로 돌아가서 다음을 수행합니다.

    • $authority$resourceUrl 변수를 업데이트합니다. 2단계에서 콘솔 출력에 지정된 값과 일치해야 합니다.

    • PowerShell 스크립트를 실행합니다. cmdlet은 Get-ADALToken 아래 예제와 유사하게 Microsoft Entra 인증 프롬프트를 트리거합니다. 2단계에서 콘솔 출력에 제공된 것과 동일한 계정을 지정합니다. 로그인에 성공하면 액세스 토큰이 클립보드에 배치됩니다.

      Visual Studio 토큰 로그인 획득

    • 로그인 계정으로 실행하는 동안 애플리케이션이 MIP API에 액세스할 수 있도록 동의해야 할 수도 있습니다. 이는 Microsoft Entra 애플리케이션 등록이 사전 동의되지 않거나("MIP SDK 설정 및 구성"에 설명된 대로) 다른 테넌트의 계정으로 로그인하는 경우(애플리케이션이 등록된 테넌트 이외의) 경우에 발생합니다. 동의를 기록하려면 동의 를 클릭하기만 하면 됩니다.

      Visual Studio 동의

  4. After pasting the access token into the prompt from step #2, your console output should show the protection templates , similar to the following example:

    *** Template List:
    Name: Confidential \ All Employees : a74f5027-f3e3-4c55-abcd-74c2ee41b607
    Name: Highly Confidential \ All Employees : bb7ed207-046a-4caf-9826-647cff56b990
    Name: Confidential : 174bc02a-6e22-4cf2-9309-cb3d47142b05
    Name: Contoso Employees Only : 667466bf-a01b-4b0a-8bbf-a79a3d96f720
    
    C:\MIP Sample Apps\ProtectionQS\Debug\ProtectionQS.exe (process 8252) exited with code 0.
    To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
    
    Press any key to continue . . .
    

    비고

    Copy and save the ID of one or more of the protection templates (for example, f42a3342-8706-4288-bd31-ebb85995028z), as you will use it in the next Quickstart.

문제 해결

C++ 애플리케이션 실행 중 문제

요약 오류 메시지 해결 방법
잘못된 액세스 토큰 예외가 발생했습니다... 액세스 토큰이 잘못되었거나 만료되었나요?

실패한 API 호출: profile_add_engine_async 실패: [class mip::P olicySyncException] 정책 획득 실패, http 상태 코드로 요청 실패: 401, x-ms-diagnostics: [2000001; reason="요청과 함께 제출된 OAuth 토큰을 구문 분석할 수 없습니다."; error_category="invalid_token"], correlationId:[35bc0023-3727-4eff-8062-000006d5d672]'

C:\VSProjects\MipDev\Quickstarts\AppInitialization\x64\Debug\AppInitialization.exe(프로세스 29924)가 코드 0으로 종료되었습니다.

아무 키나 눌러 이 창을 닫습니다. . .
프로젝트가 성공적으로 빌드되었지만 왼쪽과 비슷한 출력이 표시되는 경우 메서드에 유효하지 않거나 만료된 토큰이 있을 수 있습니다 AcquireOAuth2Token() . PowerShell 스크립트 만들기로 돌아가 액세스 토큰을 생성하고 액세스 토큰을 다시 생성하고, 다시 업데이트 AcquireOAuth2Token() 하고, 다시 빌드/다시 테스트합니다. jwt.ms 단일 페이지 웹 애플리케이션을 사용하여 토큰 및 해당 클레임을 검사하고 확인할 수도 있습니다.

다음 단계

Now that you've learned how to list the protection templates available to an authenticated user, try the next quickstart:

[Encrypt and Decrypt text](quick-protection-encrypt-decrypt text-cpp.md)