Reference.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. options.OutputName = Path.Combine(@"D:\mip\testfiles\compound\output\", Path.GetFileName(item.Key));
  2. C:\DEV\SOLUTION\TEMP\MipSdk-Dotnet-File-Quickstart-17a8a8fad4bf34d8cdac37c4dff130f603f58c7a\mip-sdk-dotnet-quickstart\TEMP\mipsdk-compoundfileprotection-9caa2757495331da6e723a8c5c1c0d9290236b4f
  3. private readonly IConfidentialClientApplication _app;
  4. ConfidentialClientApplicationOptions options = new ConfidentialClientApplicationOptions()
  5. {
  6. ClientSecret = config.AppSecret,
  7. ClientId = clientId,
  8. TenantId = tenantId,
  9. RedirectUri = redirectUri,
  10. Instance = "https://login.microsoftonline.com/"
  11. };
  12. _app = ConfidentialClientApplicationBuilder
  13. .CreateWithApplicationOptions(options)
  14. .WithRedirectUri(redirectUri)
  15. .Build();
  16. engine = CreateFileEngine(new Identity("MyService"));
  17. private IFileEngine CreateFileEngine(Identity identity)
  18. {
  19. // If the profile hasn't been created, do that first.
  20. if (profile == null)
  21. {
  22. profile = CreateFileProfile(appInfo);
  23. }
  24. // Create file settings object. Passing in empty string for the first parameter, engine ID, will cause the SDK to generate a GUID.
  25. // Locale settings are supported and should be provided based on the machine locale, particular for client applications.
  26. var engineSettings = new FileEngineSettings(identity.Email, authDelegate, "", "en-US")
  27. {
  28. // Provide the identity for service discovery.
  29. Cloud = Cloud.Commercial
  30. };
  31. // Add the IFileEngine to the profile and return.
  32. var engine = Task.Run(async () => await profile.AddEngineAsync(engineSettings)).Result;
  33. return engine;
  34. }
  35. ///////////////////////////////////////////////////////////////////////
  36. using (var stream = new FileStream(@"c:\kk\memoria.pdf", FileMode.Open, FileAccess.Read))
  37. {
  38. var decryptedStream = await action.GetDecryptedStreamAsync(stream, "memoria.pdf");
  39. if (decryptedStream.Length == 0)
  40. {
  41. Console.WriteLine("Decrypted stream is empty.");
  42. }
  43. else
  44. {
  45. decryptedStream.Position = 0;
  46. using (var outputStream = new FileStream(@"c:\kk\memoria-un.pdf", FileMode.Create, FileAccess.Write))
  47. {
  48. decryptedStream.CopyTo(outputStream);
  49. }
  50. }
  51. }
  52. ///////////////////////////////////////////////////////////////////////
  53. public string AcquireToken(Identity identity, string authority, string resource, string claims)
  54. {
  55. return AcquireTokenAsync(authority, resource, claims, isMultitenantApp).Result.AccessToken;
  56. }
  57. /// <summary>
  58. /// Implements token acquisition logic via the Microsoft Authentication Library.
  59. ///
  60. /// /// </summary>
  61. /// <param name="identity"></param>
  62. /// <param name="authority"></param>
  63. /// <param name="resource"></param>
  64. /// <param name="claims"></param>
  65. /// <returns></returns>
  66. public async Task<AuthenticationResult> AcquireTokenAsync(string authority, string resource, string claims, bool isMultiTenantApp = true)
  67. {
  68. AuthenticationResult result = null;
  69. // Append .default to the resource passed in to AcquireToken().
  70. string[] scopes = new string[] { resource[resource.Length - 1].Equals('/') ? $"{resource}.default" : $"{resource}/.default" };
  71. result = await _app.AcquireTokenForClient(scopes)
  72. .ExecuteAsync();
  73. // Return the token. The token is sent to the resource.
  74. return result;
  75. }
  76. ///////////////////////////////////////////////////////////////////////
  77. https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Client-Applications/351a92cd4066676281d9997c13e9e192db105080
  78. ///////////////////////////////////////////////////////////////////////
  79. https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/wiki/AuthenticationContext-the-connection-to-Azure-AD
  80. ///////////////////////////////////////////////////////////////////////
  81. C:\DEV\SOLUTION\IIS\microsoft-authentication-library-for-dotnet-main\tests\devapps\NetCoreTestApp
  82. C:\DEV\SOLUTION\IIS\microsoft-authentication-library-for-dotnet-main\tests
  83. ///////////////////////////////////////////////////////////////////////
  84. await Task.Delay(500).ConfigureAwait(false);
  85. ///////////////////////////////////////////////////////////////////////
  86. ///////////////////////////////////////////////////////////////////////
  87. ///////////////////////////////////////////////////////////////////////
  88. ///////////////////////////////////////////////////////////////////////
  89. ///////////////////////////////////////////////////////////////////////
  90. ///////////////////////////////////////////////////////////////////////
  91. ///////////////////////////////////////////////////////////////////////
  92. ///////////////////////////////////////////////////////////////////////
  93. ///////////////////////////////////////////////////////////////////////
  94. ///////////////////////////////////////////////////////////////////////
  95. ///////////////////////////////////////////////////////////////////////
  96. ///////////////////////////////////////////////////////////////////////
  97. ///////////////////////////////////////////////////////////////////////
  98. ///////////////////////////////////////////////////////////////////////
  99. ///////////////////////////////////////////////////////////////////////
  100. ///////////////////////////////////////////////////////////////////////
  101. ///////////////////////////////////////////////////////////////////////
  102. ///////////////////////////////////////////////////////////////////////
  103. ///////////////////////////////////////////////////////////////////////