|
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;
|
@@ -220,7 +221,8 @@ public SsoToken GetToken(SSOTokenManagerGetTokenOptions options)
|
220 | 221 | }
|
221 | 222 | catch (Exception ex)
|
222 | 223 | {
|
223 |
| - _logger.Error(ex, $"Refreshing SSOToken for [{options.StartUrl}] failed: {ex.Message}"); |
| 224 | + // Exception message from SSOIDC client has text along with HTTP Body as JSON string. |
| 225 | + _logger.Error(ex, $"Refreshing SSOToken for [{options.StartUrl}] failed: {ex.Message.Replace("{", "{{").Replace("}", "}}")}"); |
224 | 226 | //if refreshing the token failed that means the refresh token was expired.
|
225 | 227 | //if the refresh token is expired and access token is expired and if the user specifies a callback with
|
226 | 228 | //option.SupportsGettingNewToken is true then we will generate a new token.
|
@@ -484,7 +486,8 @@ public async Task<SsoToken> GetTokenAsync(SSOTokenManagerGetTokenOptions options
|
484 | 486 | }
|
485 | 487 | catch (Exception ex)
|
486 | 488 | {
|
487 |
| - _logger.Error(ex, $"Refreshing SSOToken for [{options.Session}] failed: {ex.Message}"); |
| 489 | + // Exception message from SSOIDC client has text along with HTTP Body as JSON string. |
| 490 | + _logger.Error(ex, $"Refreshing SSOToken for [{options.Session}] failed: {ex.Message.Replace("{", "{{").Replace("}", "}}")}"); |
488 | 491 | if (ssoToken.IsExpired() && options.SupportsGettingNewToken)
|
489 | 492 | {
|
490 | 493 | return await GenerateNewTokenAsync(options, cancellationToken).ConfigureAwait(false);
|
@@ -612,24 +615,11 @@ public async Task LogoutAsync(SSOTokenManagerGetTokenOptions options, Cancellati
|
612 | 615 |
|
613 | 616 | private async Task<SsoToken> GenerateNewTokenAsync(SSOTokenManagerGetTokenOptions options, CancellationToken cancellationToken = default)
|
614 | 617 | {
|
615 |
| - if (string.IsNullOrEmpty(options.ClientName)) |
616 |
| - { |
617 |
| - throw new ArgumentNullException($"Options property cannot be empty: {nameof(options.ClientName)}"); |
618 |
| - } |
| 618 | + var emptyProperties = GetEmptySSOTokenOptions(options); |
619 | 619 |
|
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 |
| 620 | + if (emptyProperties.Count > 0) |
628 | 621 | {
|
629 |
| - if (options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync == null) |
630 |
| - { |
631 |
| - throw new ArgumentNullException($"Options property cannot be empty: {nameof(options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync)}"); |
632 |
| - } |
| 622 | + throw new AmazonClientException($"Error generating new SSO token. Options properties cannot be empty: {string.Join(", ", emptyProperties)}"); |
633 | 623 | }
|
634 | 624 |
|
635 | 625 | var request = new GetSsoTokenRequest
|
@@ -664,6 +654,33 @@ private async Task<SsoToken> GenerateNewTokenAsync(SSOTokenManagerGetTokenOption
|
664 | 654 |
|
665 | 655 | return token;
|
666 | 656 | }
|
| 657 | + |
| 658 | + private static List<string> GetEmptySSOTokenOptions(SSOTokenManagerGetTokenOptions options) |
| 659 | + { |
| 660 | + var emptyProperties = new List<string>(); |
| 661 | + |
| 662 | + if (string.IsNullOrEmpty(options.ClientName)) |
| 663 | + { |
| 664 | + emptyProperties.Add(nameof(options.ClientName)); |
| 665 | + } |
| 666 | + |
| 667 | + if (options.PkceFlowOptions == null) |
| 668 | + { |
| 669 | + if (options.SsoVerificationCallback == null) |
| 670 | + { |
| 671 | + emptyProperties.Add(nameof(options.SsoVerificationCallback)); |
| 672 | + } |
| 673 | + } |
| 674 | + else |
| 675 | + { |
| 676 | + if (options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync == null) |
| 677 | + { |
| 678 | + emptyProperties.Add(nameof(options.PkceFlowOptions.RetrieveAuthorizationCodeCallbackAsync)); |
| 679 | + } |
| 680 | + } |
| 681 | + |
| 682 | + return emptyProperties; |
| 683 | + } |
667 | 684 | #endif
|
668 | 685 |
|
669 | 686 | private static SsoToken MapGetSsoTokenResponseToSsoToken(GetSsoTokenResponse response, string session)
|
|
0 commit comments