Beispiel #1
0
        /// <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;
            }
        }
Beispiel #2
0
        /// <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);
        }
Beispiel #4
0
        /// <summary>
        /// Creates an IFileProfile and returns.
        /// IFileProfile is the root of all MIP SDK File API operations. Typically only one should be created per app.
        /// </summary>
        /// <param name="appInfo"></param>
        /// <param name="authDelegate"></param>
        /// <returns></returns>
        private IFileProfile CreateFileProfile(ApplicationInfo appInfo, ref AuthDelegateImplementation authDelegate)
        {
            mipContext = MIP.CreateMipContext(appInfo, "mip_data", LogLevel.Trace, null, null);

            // Initialize file profile settings to create/use local state.
            var profileSettings = new FileProfileSettings(mipContext, CacheStorageType.OnDiskEncrypted, new ConsentDelegateImplementation());

            // Use MIP.LoadFileProfileAsync() providing settings to create IFileProfile.
            // IFileProfile is the root of all SDK operations for a given application.
            var profile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result;

            return(profile);
        }
Beispiel #5
0
        /// <summary>
        /// Creates an IFileProfile and returns.
        /// IFileProfile is the root of all MIP SDK File API operations. Typically only one should be created per app.
        /// </summary>
        /// <param name="appInfo"></param>
        /// <param name="authDelegate"></param>
        /// <returns></returns>
        private IFileProfile CreateFileProfile(ApplicationInfo appInfo, ref AuthDelegateImplementation authDelegate)
        {
            try
            {
                // Initialize file profile settings to create/use local state.
                var profileSettings = new FileProfileSettings("mip_data", false, authDelegate, new ConsentDelegateImplementation(), appInfo, LogLevel.Trace);

                // Use MIP.LoadFileProfileAsync() providing settings to create IFileProfile.
                // IFileProfile is the root of all SDK operations for a given application.
                var profile = Task.Run(async() => await MIP.LoadFileProfileAsync(profileSettings)).Result;
                return(profile);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }