|
15 | 15 |
|
16 | 16 | using System;
|
17 | 17 | using System.Collections.Concurrent;
|
| 18 | +using System.Collections.Generic; |
18 | 19 | using System.Net;
|
19 | 20 | using System.Threading;
|
20 | 21 | using System.Threading.Tasks;
|
@@ -484,7 +485,8 @@ public async Task<SsoToken> GetTokenAsync(SSOTokenManagerGetTokenOptions options
|
484 | 485 | }
|
485 | 486 | catch (Exception ex)
|
486 | 487 | {
|
487 |
| - _logger.Error(ex, $"Refreshing SSOToken for [{options.Session}] failed: {ex.Message}"); |
| 488 | + // Exception message from SSOIDC client has text along with HTTP Body as JSON string. |
| 489 | + _logger.Error(ex, $"Refreshing SSOToken for [{options.Session}] failed: {ex.Message.Replace("{", "{{").Replace("}", "}}")}"); |
488 | 490 | if (ssoToken.IsExpired() && options.SupportsGettingNewToken)
|
489 | 491 | {
|
490 | 492 | return await GenerateNewTokenAsync(options, cancellationToken).ConfigureAwait(false);
|
@@ -612,24 +614,11 @@ public async Task LogoutAsync(SSOTokenManagerGetTokenOptions options, Cancellati
|
612 | 614 |
|
613 | 615 | private async Task<SsoToken> GenerateNewTokenAsync(SSOTokenManagerGetTokenOptions options, CancellationToken cancellationToken = default)
|
614 | 616 | {
|
615 |
| - if (string.IsNullOrEmpty(options.ClientName)) |
616 |
| - { |
617 |
| - throw new ArgumentNullException($"Options property cannot be empty: {nameof(options.ClientName)}"); |
618 |
| - } |
| 617 | + var emptyProperties = GetEmptySSOTokenOptions(options); |
619 | 618 |
|
620 |
| - if (options.PkceFlowOptions == null) |
621 |
| - { |
622 |
| - if (options.SsoVerificationCallback == null) |
623 |
| - { |
624 |
| - throw new ArgumentNullException($"Options property cannot be empty: {nameof(options.SsoVerificationCallback)}"); |
625 |
| - } |
626 |
| - } |
627 |
| - else |
| 619 | + if (emptyProperties.Count > 0) |
628 | 620 | {
|
629 |
| - if (options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync == null) |
630 |
| - { |
631 |
| - throw new ArgumentNullException($"Options property cannot be empty: {nameof(options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync)}"); |
632 |
| - } |
| 621 | + throw new AmazonClientException($"Error generating new SSO token. Options properties cannot be empty: {string.Join(", ", emptyProperties)}"); |
633 | 622 | }
|
634 | 623 |
|
635 | 624 | var request = new GetSsoTokenRequest
|
@@ -664,6 +653,33 @@ private async Task<SsoToken> GenerateNewTokenAsync(SSOTokenManagerGetTokenOption
|
664 | 653 |
|
665 | 654 | return token;
|
666 | 655 | }
|
| 656 | + |
| 657 | + private List<string> GetEmptySSOTokenOptions(SSOTokenManagerGetTokenOptions options) |
| 658 | + { |
| 659 | + var emptyProperties = new List<string>(); |
| 660 | + |
| 661 | + if (string.IsNullOrEmpty(options.ClientName)) |
| 662 | + { |
| 663 | + emptyProperties.Add(nameof(options.ClientName)); |
| 664 | + } |
| 665 | + |
| 666 | + if (options.PkceFlowOptions == null) |
| 667 | + { |
| 668 | + if (options.SsoVerificationCallback == null) |
| 669 | + { |
| 670 | + emptyProperties.Add(nameof(options.SsoVerificationCallback)); |
| 671 | + } |
| 672 | + } |
| 673 | + else |
| 674 | + { |
| 675 | + if (options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync == null) |
| 676 | + { |
| 677 | + emptyProperties.Add(nameof(options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync)); |
| 678 | + } |
| 679 | + } |
| 680 | + |
| 681 | + return emptyProperties; |
| 682 | + } |
667 | 683 | #endif
|
668 | 684 |
|
669 | 685 | private static SsoToken MapGetSsoTokenResponseToSsoToken(GetSsoTokenResponse response, string session)
|
|
0 commit comments