in wwauth/Google.Solutions.WWAuth/View/VerifyConfigurationViewModel.cs [218:358]
public async Task PerformTestAsync(
CancellationToken cancellationToken)
{
this.AcquireTokenStatusImage = Resources.Wait_16;
this.ExchangeTokenStatusImage = Resources.Wait_16;
this.ImpersonateStatusImage = Resources.Wait_16;
this.IsCancelButtonEnabled = true;
this.IsOkButtonEnabled = false;
var user = WindowsIdentity.GetCurrent().Name;
this.WindowTitle = $"Test configuration as {user}";
try
{
cancellationToken.ThrowIfCancellationRequested();
//
// (1) Acquire token.
//
ISubjectToken externalToken;
try
{
externalToken = await this.tokenAdapter
.AcquireTokenAsync(
TokenAcquisitionOptions.ExtensiveValidation,
cancellationToken)
.ConfigureAwait(true);
this.AcquireTokenStatusImage = Resources.Success_16;
this.IsShowExternalTokenDetailsLinkEnabled = true;
this.ExternalToken = externalToken;
}
catch (Exception)
{
this.AcquireTokenStatusImage = Resources.Error_16;
this.ExchangeTokenStatusImage = null;
this.ImpersonateStatusImage = null;
throw;
}
//
// (2) Exchange token.
//
TokenResponse stsToken;
try
{
stsToken = await this.stsAdapter
.ExchangeTokenAsync(
externalToken,
CredentialConfiguration.DefaultScopes,
cancellationToken)
.ConfigureAwait(true);
this.ExchangeTokenStatusImage = Resources.Success_16;
}
catch (Exception)
{
this.ExchangeTokenStatusImage = Resources.Error_16;
this.ImpersonateStatusImage = null;
throw;
}
//
// (3) Try to introspect STS token.
//
try
{
this.StsToken = await this.stsAdapter
.IntrospectTokenAsync(
stsToken.AccessToken,
cancellationToken)
.ConfigureAwait(true);
this.IsShowStsTokenDetailsLinkEnabled = true;
}
catch
{
this.IsShowStsTokenDetailsLinkEnabled = false;
}
if (this.serviceAccountAdapter.IsEnabled)
{
//
// (4) Impersonate.
//
try
{
if (!await this.serviceAccountAdapter
.ExistsAsync(cancellationToken)
.ConfigureAwait(true))
{
throw new ArgumentException(
$"Service account {serviceAccountAdapter.ServiceAccountEmail}' does not exist");
}
var token = await serviceAccountAdapter
.ImpersonateAsync(
stsToken.AccessToken,
CredentialConfiguration.DefaultScopes,
cancellationToken)
.ConfigureAwait(true);
this.ServiceAccountToken = await serviceAccountAdapter
.IntrospectTokenAsync(
token.AccessToken,
cancellationToken)
.ConfigureAwait(true);
this.IsShowServiceAccountTokenDetailsLinkEnabled = true;
this.ImpersonateStatusImage = Resources.Success_16;
}
catch (Exception)
{
this.ImpersonateStatusImage = Resources.Error_16;
throw;
}
}
this.ResultImage = Resources.Success_16;
this.ResultText = "Test completed successfully.";
this.IsResultPanelVisible = true;
}
catch (OperationCanceledException)
{ }
catch (Exception e)
{
this.logger.Error(e, "{0}", e.Message);
this.ResultImage = Resources.Error_16;
this.ResultText = e.FullMessage();
this.IsResultPanelVisible = true;
this.IsLogsButtonEnabled = true;
}
finally
{
this.IsCancelButtonEnabled = false;
this.IsOkButtonEnabled = true;
}
}