/// <summary> /// Creates a file engine, associating the engine with the specified identity. /// File engines are generally created per-user in an application. /// IFileEngine implements all operations for fetching labels and sensitivity types. /// IFileHandlers are added to engines to perform labeling operations. /// </summary> /// <param name="identity"></param> /// <returns></returns> private IFileEngine CreateFileEngine(Identity identity) { // If the profile hasn't been created, do that first. if (profile == null) { profile = CreateFileProfile(appInfo); } var configuredFunctions = new Dictionary <FunctionalityFilterType, bool>(); configuredFunctions.Add(FunctionalityFilterType.DoubleKeyProtection, true); // Create file settings object. Passing in empty string for the first parameter, engine ID, will cause the SDK to generate a GUID. // Locale settings are supported and should be provided based on the machine locale, particular for client applications. var engineSettings = new FileEngineSettings(identity.Email, authDelegate, "", "en-US") { // Provide the identity for service discovery. Identity = identity, ConfiguredFunctionality = configuredFunctions }; // Add the IFileEngine to the profile and return. var engine = Task.Run(async() => await profile.AddEngineAsync(engineSettings)).Result; return(engine); }
/// <summary> /// Constructor for Action class. Pass in AppInfo to simplify passing settings to AuthDelegate. /// </summary> /// <param name="appInfo"></param> public Action(ApplicationInfo appInfo) { this.appInfo = appInfo; // Initialize AuthDelegateImplementation using AppInfo. authDelegate = new AuthDelegateImplementation(this.appInfo); // Initialize SDK DLLs. If DLLs are missing or wrong type, this will throw an exception try { MIP.Initialize(MipComponent.File); // This method in AuthDelegateImplementation triggers auth against Graph so that we can get the user ID. var id = authDelegate.GetUserIdentity(); // Create profile. profile = CreateFileProfile(appInfo, ref authDelegate); // Create engine providing Identity from authDelegate to assist with service discovery. engine = CreateFileEngine(id); } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates a file engine, associating the engine with the specified identity. /// File engines are generally created per-user in an application. /// IFileEngine implements all operations for fetching labels and sensitivity types. /// IFileHandlers are added to engines to perform labeling operations. /// </summary> /// <param name="identity"></param> /// <returns></returns> private IFileEngine CreateFileEngine(Identity identity) { try { // If the profile hasn't been created, do that first. if (profile == null) { profile = CreateFileProfile(appInfo, ref authDelegate); } // Create file settings object. Passing in empty string for the first parameter, engine ID, will cause the SDK to generate a GUID. // Locale settings are supported and should be provided based on the machine locale, particular for client applications. var engineSettings = new FileEngineSettings("", "", "en-US") { // Provide the identity for service discovery. Identity = identity }; // Add the IFileEngine to the profile and return. var engine = Task.Run(async() => await profile.AddEngineAsync(engineSettings)).Result; return(engine); } catch (Exception ex) { throw ex; } }
/// <summary> /// Constructor for Action class. Pass in AppInfo to simplify passing settings to AuthDelegate. /// </summary> /// <param name="appInfo"></param> public Action(ApplicationInfo appInfo) { this.appInfo = appInfo; // Initialize AuthDelegateImplementation using AppInfo. authDelegate = new AuthDelegateImplementation(this.appInfo); // Initialize SDK DLLs. If DLLs are missing or wrong type, this will throw an exception MIP.Initialize(MipComponent.File); // We must construct a service principal identity mail address as it can't be fetched from the token. // Here, we set it to be [email protected], but the SDK will accept any properly formatted email address. Identity id = new Identity(String.Format("{0}@{1}", appInfo.ApplicationId, tenant)) { // DelegatedEmail = "*****@*****.**" // Use this if you want the app to protect on behalf of a user. // That user owns the protected content. }; // Create profile. profile = CreateFileProfile(appInfo, ref authDelegate); // Create engine providing Identity from authDelegate to assist with service discovery. engine = CreateFileEngine(id); }
/// <summary> /// Constructor for Action class. Pass in AppInfo to simplify passing settings to AuthDelegate. /// </summary> /// <param name="appInfo"></param> public Action(ApplicationInfo appInfo) { this.appInfo = appInfo; // Initialize AuthDelegateImplementation using AppInfo. authDelegate = new AuthDelegateImplementation(this.appInfo); // Initialize SDK DLLs. If DLLs are missing or wrong type, this will throw an exception MIP.Initialize(MipComponent.File); // This method in AuthDelegateImplementation triggers auth against Graph so that we can get the user ID. //var id = authDelegate.GetUserIdentity(); // Prompt one time for a user identity. // This identity is used for service discovery. If MDE SRV record isn't registered properly, we will default to AIP service. Console.WriteLine("The Identity object provides hints on service discovery."); Console.WriteLine("If MDE is properly configured, the mail suffix of the user will be used for discovery."); Console.WriteLine("It will find the MDE record and use the on-prem AD RMS and ADFS for auth."); Console.Write("Enter a user name, either email or UPN: "); identity = new Identity(Console.ReadLine()); // Create profile. profile = CreateFileProfile(appInfo, ref authDelegate); // Create engine providing Identity from authDelegate to assist with service discovery. engine = CreateFileEngine(identity); }
/// <summary> /// Creates a new IFileProfile object and stores in private _fileProfile. /// </summary> private void CreateFileProfile() { try { var profileSettings = new FileProfileSettings(mipPath, false, _authDelegate, new ConsentDelegateImplementation(), _appInfo, LogLevel.Trace); _fileProfile = Task.Run(async() => await new FileProfileFactory().LoadAsync(profileSettings)).Result; } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates a new IFileProfile object and stores in private _fileProfile. /// </summary> private void CreateFileProfile() { try { mipContext = MIP.CreateMipContext(appInfo, mipPath, LogLevel.Error, null, null); var profileSettings = new FileProfileSettings(mipContext, CacheStorageType.OnDisk, new ConsentDelegateImplementation()); fileProfile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result; } catch (Exception ex) { throw ex; } }