Skip to content

Commit 182b3eb

Browse files
authored
Merge pull request Azure-Samples#4 from Azure-Samples/release/1.3
Release 1.3 Updates
2 parents 05453de + feaf9cf commit 182b3eb

File tree

5 files changed

+49
-58
lines changed

5 files changed

+49
-58
lines changed

mipsdk-protectionapi-cpp-sample-basic/action.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,31 @@ namespace sample {
7676

7777
Action::~Action()
7878
{
79-
mProfile = nullptr;
8079
mEngine = nullptr;
81-
mip::ReleaseAllResources();
80+
mProfile = nullptr;
81+
mMipContext = nullptr;
8282
}
8383

8484
void sample::file::Action::AddNewProtectionProfile()
8585
{
86-
ProtectionProfile::Settings profileSettings("mip_data", false, mAuthDelegate, std::make_shared<sample::consent::ConsentDelegateImpl>(), std::make_shared<ProtectionProfileObserverImpl>(), mAppInfo);
86+
//Create MipContext
87+
mMipContext = mip::MipContext::Create(
88+
mAppInfo,
89+
"mip_data",
90+
mip::LogLevel::Trace,
91+
false,
92+
nullptr /*loggerDelegateOverride*/,
93+
nullptr /*telemetryOverride*/
94+
);
95+
96+
// Initialize ProtectionProfileSettings using MipContext
97+
ProtectionProfile::Settings profileSettings(mMipContext,
98+
mip::CacheStorageType::OnDiskEncrypted,
99+
mAuthDelegate,
100+
std::make_shared<sample::consent::ConsentDelegateImpl>(),
101+
std::make_shared<ProtectionProfileObserverImpl>()
102+
);
103+
87104
auto profilePromise = std::make_shared<std::promise<std::shared_ptr<ProtectionProfile>>>();
88105
auto profileFuture = profilePromise->get_future();
89106
ProtectionProfile::LoadAsync(profileSettings, profilePromise);

mipsdk-protectionapi-cpp-sample-basic/action.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <memory>
3333
#include <string>
3434

35+
#include "mip/mip_context.h"
3536
#include "mip/common_types.h"
3637
#include "mip/protection/protection_profile.h"
3738
#include "mip/protection/protection_engine.h"
@@ -77,6 +78,7 @@ namespace sample {
7778
std::shared_ptr<mip::ProtectionDescriptor> CreateProtectionDescriptor(const ProtectionOptions protectionOptions);
7879

7980
std::shared_ptr<sample::auth::AuthDelegateImpl> mAuthDelegate; // AuthDelegateImpl object that will be used throughout the sample to store auth details.
81+
std::shared_ptr<mip::MipContext> mMipContext;
8082
std::shared_ptr<mip::ProtectionProfile> mProfile; // mip::FileProfile object to store/load state information
8183
std::shared_ptr<mip::ProtectionEngine> mEngine; // mip::FileEngine object to handle user-specific actions.
8284
std::shared_ptr<sample::consent::ConsentDelegateImpl> mConsentDelegate; // Implements consent flow. Review consent_delegate_impl.cpp for implementation details.

mipsdk-protectionapi-cpp-sample-basic/auth.py

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,32 @@
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
# THE SOFTWARE.
2424
#
25+
# make sure to run pip install adal, first.
26+
# for non-windows setup, review https://github.com/AzureAD/azure-activedirectory-library-for-python/wiki/ADAL-basics
2527

2628
import getopt
2729
import sys
2830
import json
29-
import urllib
30-
import urllib2
3131
import re
32-
33-
#
34-
# This script acquires auth tokens directly via a simple http request. This is
35-
# included only as a means to acquire auth tokens for use by the sample apps
36-
# and is not intended for use in production code. It will only work for tenants
37-
# that support straightforward username/password http authentication.
38-
#
39-
# For proper auth integration, please use Azure Active Directory Authentication
40-
# Library (ADAL), Active Directory v2 Libraries (MSAL), or other OAuth 2.0
41-
# libraries:
42-
#
43-
# https:// docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-libraries
44-
# https:// docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-libraries
45-
#
32+
from adal import AuthenticationContext
4633

4734
def printUsage():
4835
print('auth.py -u <username> -p <password> -a <authority> -r <resource> -c <clientId>')
4936

5037
def main(argv):
5138
try:
5239
options, args = getopt.getopt(argv, 'hu:p:a:r:c:')
53-
except getopt.GetoptFailure:
40+
except getopt.GetoptError:
5441
printUsage()
5542
sys.exit(-1)
5643

5744
username = ''
5845
password = ''
5946
authority = ''
6047
resource = ''
61-
clientId = ''
6248

49+
clientId = ''
50+
6351
for option, arg in options:
6452
if option == '-h':
6553
printUsage()
@@ -84,31 +72,11 @@ def main(argv):
8472
regex = re.compile('^(.*[\/])')
8573
match = regex.match(authority)
8674
authority = match.group()
87-
authority = authority + 'common/oauth2/token'
88-
89-
# Build REST call
90-
headers = {
91-
'Content-Type': 'application/x-www-form-urlencoded',
92-
'Accept': 'application/json'
93-
}
94-
95-
params = {
96-
'resource': resource,
97-
'client_id': clientId,
98-
'grant_type': 'password',
99-
'username': username,
100-
'password': password
101-
}
102-
103-
req = urllib2.Request(
104-
url = authority,
105-
headers = headers,
106-
data = urllib.urlencode(params))
75+
authority = authority + username.split('@')[1]
10776

108-
f = urllib2.urlopen(req)
109-
response = f.read()
110-
f.close()
111-
sys.stdout.write(json.loads(response)['access_token'])
77+
auth_context = AuthenticationContext(authority)
78+
token = auth_context.acquire_token_with_username_password(resource, username, password, clientId)
79+
print(token["accessToken"])
11280

113-
if __name__ == '__main__':
81+
if __name__ == '__main__':
11482
main(sys.argv[1:])

mipsdk-protectionapi-cpp-sample-basic/main.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,23 @@ int main()
5454
string plaintext;
5555
string ciphertext;
5656
string decryptedText;
57+
std::string clientId = "YOUR CLIENT ID";
58+
std::string appName = "YOUR APP NAME";
59+
std::string appVersion = "YOUR APP VERSION";
60+
std::string userName = "YOUR TEST USER";
61+
std::string password = "YOUR TEST USER PASSWORD";
62+
5763

5864
// Create the mip::ApplicationInfo object.
5965
// Client ID should be the client ID registered in Azure AD for your custom application.
6066
// Friendly Name should be the name of the application as it should appear in reports.
61-
// Version should should be version number of the application you're writing. This data will show in logs.
62-
mip::ApplicationInfo appInfo{ "YOUR CLIENT ID HERE", "YOUR APP NAME HERE", "YOUR APP VERSION" };
63-
64-
// All actions for this tutorial project are implemented in samples::file::Action
65-
// Source files are Action.h/cpp.
66-
// "File" was chosen because this example is specifically for the MIP SDK File API.
67+
mip::ApplicationInfo appInfo{ clientId, appName, appVersion };
68+
69+
// All actions for this tutorial project are implemented in samples::policy::Action
70+
// Source files are Action.h/cpp.
6771
// Action's constructor takes in the mip::ApplicationInfo object and uses the client ID for auth.
6872
// Username and password are required in this sample as the oauth2 token is obtained via Python script and basic auth.
69-
Action action = Action(appInfo, "YOUR TEST USER NAME","YOUR TEST USER PASSWORD");
73+
Action action = Action(appInfo, userName, password);
7074

7175
while (true)
7276
{

mipsdk-protectionapi-cpp-sample-basic/mipsdk-protectionapi-cpp-sample-basic.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@
2323
<ProjectGuid>{F8C94F02-CAD2-4449-843F-D6ABCD8A6634}</ProjectGuid>
2424
<Keyword>Win32Proj</Keyword>
2525
<RootNamespace>mipsdk-protectionapi-cpp-sample-basic</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
3030
<ConfigurationType>Application</ConfigurationType>
3131
<UseDebugLibraries>true</UseDebugLibraries>
32-
<PlatformToolset>v141</PlatformToolset>
32+
<PlatformToolset>v142</PlatformToolset>
3333
<CharacterSet>Unicode</CharacterSet>
3434
</PropertyGroup>
3535
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
3636
<ConfigurationType>Application</ConfigurationType>
3737
<UseDebugLibraries>false</UseDebugLibraries>
38-
<PlatformToolset>v141</PlatformToolset>
38+
<PlatformToolset>v142</PlatformToolset>
3939
<WholeProgramOptimization>true</WholeProgramOptimization>
4040
<CharacterSet>Unicode</CharacterSet>
4141
</PropertyGroup>
4242
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
4343
<ConfigurationType>Application</ConfigurationType>
4444
<UseDebugLibraries>true</UseDebugLibraries>
45-
<PlatformToolset>v141</PlatformToolset>
45+
<PlatformToolset>v142</PlatformToolset>
4646
<CharacterSet>Unicode</CharacterSet>
4747
</PropertyGroup>
4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
4949
<ConfigurationType>Application</ConfigurationType>
5050
<UseDebugLibraries>false</UseDebugLibraries>
51-
<PlatformToolset>v141</PlatformToolset>
51+
<PlatformToolset>v142</PlatformToolset>
5252
<WholeProgramOptimization>true</WholeProgramOptimization>
5353
<CharacterSet>Unicode</CharacterSet>
5454
</PropertyGroup>

0 commit comments

Comments
 (0)