暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CredentialsUIImpl.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using UnityEditor;
  3. using Codice.CM.Common;
  4. using System.Threading.Tasks;
  5. using Codice.Client.Common;
  6. using Codice.Client.Common.Connection;
  7. using PlasticGui;
  8. using Unity.PlasticSCM.Editor.UI;
  9. using Codice.Client.Common.Threading;
  10. using Unity.PlasticSCM.Editor.WebApi;
  11. namespace Unity.PlasticSCM.Editor.Configuration
  12. {
  13. internal class CredentialsUiImpl : AskCredentialsToUser.IGui
  14. {
  15. AskCredentialsToUser.DialogData AskCredentialsToUser.IGui.AskUserForCredentials(string servername, SEIDWorkingMode seidWorkingMode)
  16. {
  17. AskCredentialsToUser.DialogData result = null;
  18. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  19. return result;
  20. GUIActionRunner.RunGUIAction(delegate
  21. {
  22. result = CredentialsDialog.RequestCredentials(
  23. servername, seidWorkingMode, ParentWindow.Get());
  24. });
  25. return result;
  26. }
  27. void AskCredentialsToUser.IGui.ShowSaveProfileErrorMessage(string message)
  28. {
  29. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  30. return;
  31. GUIActionRunner.RunGUIAction(delegate
  32. {
  33. GuiMessage.ShowError(string.Format(
  34. PlasticLocalization.GetString(
  35. PlasticLocalization.Name.CredentialsErrorSavingProfile),
  36. message));
  37. });
  38. }
  39. AskCredentialsToUser.DialogData AskCredentialsToUser.IGui.AskUserForOidcCredentials(
  40. string server)
  41. {
  42. throw new NotImplementedException("OIDC authentication not supported yet.");
  43. }
  44. AskCredentialsToUser.DialogData AskCredentialsToUser.IGui.AskUserForSamlCredentials(
  45. string server)
  46. {
  47. throw new NotImplementedException("SAML authentication not supported yet.");
  48. }
  49. AskCredentialsToUser.DialogData AskCredentialsToUser.IGui.AskUserForSsoCredentials(
  50. string cloudServer)
  51. {
  52. AskCredentialsToUser.DialogData result = null;
  53. if (!PlasticPlugin.ConnectionMonitor.IsConnected)
  54. return result;
  55. GUIActionRunner.RunGUIAction(delegate
  56. {
  57. result = RunSSOCredentialsRequest(
  58. cloudServer, CloudProjectSettings.accessToken);
  59. });
  60. return result;
  61. }
  62. AskCredentialsToUser.DialogData RunSSOCredentialsRequest(
  63. string cloudServer,
  64. string unityAccessToken)
  65. {
  66. if (string.IsNullOrEmpty(unityAccessToken))
  67. {
  68. return SSOCredentialsDialog.RequestCredentials(
  69. cloudServer, ParentWindow.Get());
  70. }
  71. TokenExchangeResponse tokenExchangeResponse =
  72. WaitUntilTokenExchange(unityAccessToken);
  73. // There is no internet connection, so no way to get credentials
  74. if (tokenExchangeResponse == null)
  75. {
  76. return new AskCredentialsToUser.DialogData(
  77. false, null, null, false,
  78. SEIDWorkingMode.SSOWorkingMode);
  79. }
  80. if (tokenExchangeResponse.Error == null)
  81. {
  82. return new AskCredentialsToUser.DialogData(
  83. true,
  84. tokenExchangeResponse.User,
  85. tokenExchangeResponse.AccessToken,
  86. false,
  87. SEIDWorkingMode.SSOWorkingMode);
  88. }
  89. return SSOCredentialsDialog.RequestCredentials(
  90. cloudServer, ParentWindow.Get());
  91. }
  92. static TokenExchangeResponse WaitUntilTokenExchange(
  93. string unityAccessToken)
  94. {
  95. TokenExchangeResponse result = null;
  96. Task.Run(() =>
  97. {
  98. try
  99. {
  100. result = WebRestApiClient.PlasticScm.
  101. TokenExchange(unityAccessToken);
  102. }
  103. catch (Exception ex)
  104. {
  105. ExceptionsHandler.LogException(
  106. "CredentialsUiImpl", ex);
  107. }
  108. }).Wait();
  109. return result;
  110. }
  111. }
  112. }