123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- options.OutputName = Path.Combine(@"D:\mip\testfiles\compound\output\", Path.GetFileName(item.Key));
- C:\DEV\SOLUTION\TEMP\MipSdk-Dotnet-File-Quickstart-17a8a8fad4bf34d8cdac37c4dff130f603f58c7a\mip-sdk-dotnet-quickstart\TEMP\mipsdk-compoundfileprotection-9caa2757495331da6e723a8c5c1c0d9290236b4f
- private readonly IConfidentialClientApplication _app;
- ConfidentialClientApplicationOptions options = new ConfidentialClientApplicationOptions()
- {
- ClientSecret = config.AppSecret,
- ClientId = clientId,
- TenantId = tenantId,
- RedirectUri = redirectUri,
- Instance = "https://login.microsoftonline.com/"
- };
- _app = ConfidentialClientApplicationBuilder
- .CreateWithApplicationOptions(options)
- .WithRedirectUri(redirectUri)
- .Build();
- engine = CreateFileEngine(new Identity("MyService"));
- private IFileEngine CreateFileEngine(Identity identity)
- {
- // If the profile hasn't been created, do that first.
- if (profile == null)
- {
- profile = CreateFileProfile(appInfo);
- }
- // 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.
- Cloud = Cloud.Commercial
- };
- // Add the IFileEngine to the profile and return.
- var engine = Task.Run(async () => await profile.AddEngineAsync(engineSettings)).Result;
- return engine;
- }
- ///////////////////////////////////////////////////////////////////////
- using (var stream = new FileStream(@"c:\kk\memoria.pdf", FileMode.Open, FileAccess.Read))
- {
- var decryptedStream = await action.GetDecryptedStreamAsync(stream, "memoria.pdf");
- if (decryptedStream.Length == 0)
- {
- Console.WriteLine("Decrypted stream is empty.");
- }
- else
- {
- decryptedStream.Position = 0;
- using (var outputStream = new FileStream(@"c:\kk\memoria-un.pdf", FileMode.Create, FileAccess.Write))
- {
- decryptedStream.CopyTo(outputStream);
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////
- public string AcquireToken(Identity identity, string authority, string resource, string claims)
- {
- return AcquireTokenAsync(authority, resource, claims, isMultitenantApp).Result.AccessToken;
- }
- /// <summary>
- /// Implements token acquisition logic via the Microsoft Authentication Library.
- ///
- /// /// </summary>
- /// <param name="identity"></param>
- /// <param name="authority"></param>
- /// <param name="resource"></param>
- /// <param name="claims"></param>
- /// <returns></returns>
- public async Task<AuthenticationResult> AcquireTokenAsync(string authority, string resource, string claims, bool isMultiTenantApp = true)
- {
- AuthenticationResult result = null;
- // Append .default to the resource passed in to AcquireToken().
- string[] scopes = new string[] { resource[resource.Length - 1].Equals('/') ? $"{resource}.default" : $"{resource}/.default" };
- result = await _app.AcquireTokenForClient(scopes)
- .ExecuteAsync();
- // Return the token. The token is sent to the resource.
- return result;
- }
- ///////////////////////////////////////////////////////////////////////
- https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Client-Applications/351a92cd4066676281d9997c13e9e192db105080
- ///////////////////////////////////////////////////////////////////////
- https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/wiki/AuthenticationContext-the-connection-to-Azure-AD
- ///////////////////////////////////////////////////////////////////////
- C:\DEV\SOLUTION\IIS\microsoft-authentication-library-for-dotnet-main\tests\devapps\NetCoreTestApp
- C:\DEV\SOLUTION\IIS\microsoft-authentication-library-for-dotnet-main\tests
- ///////////////////////////////////////////////////////////////////////
- await Task.Delay(500).ConfigureAwait(false);
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
|