Skip to content

Commit df57575

Browse files
committed
Changed the default value of SSOAWSCredentialsOptions.SupportsGettingNewToken as false and improved error messaging if required SSO options are missing while generating new credentials.
1 parent db805ae commit df57575

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"Changed the default value of SSOAWSCredentialsOptions.SupportsGettingNewToken as false and improved error messaging if required SSO options are missing while generating new credentials."
5+
],
6+
"type": "patch",
7+
"updateMinimum": true
8+
}
9+
}

sdk/src/Core/Amazon.Runtime/Credentials/Internal/_bcl+netstandard/SSOTokenManager.cs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Collections.Concurrent;
18+
using System.Collections.Generic;
1819
using System.Net;
1920
using System.Threading;
2021
using System.Threading.Tasks;
@@ -484,7 +485,8 @@ public async Task<SsoToken> GetTokenAsync(SSOTokenManagerGetTokenOptions options
484485
}
485486
catch (Exception ex)
486487
{
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("}", "}}")}");
488490
if (ssoToken.IsExpired() && options.SupportsGettingNewToken)
489491
{
490492
return await GenerateNewTokenAsync(options, cancellationToken).ConfigureAwait(false);
@@ -612,24 +614,11 @@ public async Task LogoutAsync(SSOTokenManagerGetTokenOptions options, Cancellati
612614

613615
private async Task<SsoToken> GenerateNewTokenAsync(SSOTokenManagerGetTokenOptions options, CancellationToken cancellationToken = default)
614616
{
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);
619618

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)
628620
{
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)}");
633622
}
634623

635624
var request = new GetSsoTokenRequest
@@ -664,6 +653,33 @@ private async Task<SsoToken> GenerateNewTokenAsync(SSOTokenManagerGetTokenOption
664653

665654
return token;
666655
}
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+
}
667683
#endif
668684

669685
private static SsoToken MapGetSsoTokenResponseToSsoToken(GetSsoTokenResponse response, string session)

sdk/src/Core/Amazon.Runtime/Credentials/_bcl+netstandard/SSOAWSCredentialsOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class SSOAWSCredentialsOptions
9494
/// NOTE: If setting to <c>true</c>, either <see cref="SsoVerificationCallback"/> or <see cref="PkceFlowOptions"/> must
9595
/// also be set for authorization flow to succeed.
9696
/// </summary>
97-
public bool SupportsGettingNewToken { get; set; } = true;
97+
public bool SupportsGettingNewToken { get; set; } = false;
9898

9999
/// <summary>
100100
/// The proxy settings to use when calling SSOOIDC and SSO Services.

0 commit comments

Comments
 (0)