Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor exception handling and minor code improvements. #1744

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task<IActionResult> OnPost()
{
props.IsPersistent = true;
props.ExpiresUtc = DateTimeOffset.UtcNow.Add(LoginOptions.RememberMeLoginDuration);
};
}

// issue authentication cookie with subject ID and username
var isuser = new IdentityServerUser(user.SubjectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task<IActionResult> OnPost()
{
props.IsPersistent = true;
props.ExpiresUtc = DateTimeOffset.UtcNow.Add(LoginOptions.RememberMeLoginDuration);
};
}

// issue authentication cookie with subject ID and username
var isuser = new IdentityServerUser(user.SubjectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task<IActionResult> OnPost()
{
props.IsPersistent = true;
props.ExpiresUtc = DateTimeOffset.UtcNow.Add(LoginOptions.RememberMeLoginDuration);
};
}

// issue authentication cookie with subject ID and username
var isuser = new IdentityServerUser(user.SubjectId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void ValidateLicense()
return;
}

DebugLog.Invoke("The Duende license key details: {@license}", new[] { License });
DebugLog.Invoke("The Duende license key details: {@license}", new object[] { License });

var errors = new List<string>();

Expand All @@ -100,7 +100,7 @@ protected void ValidateLicense()

ErrorLog.Invoke(
"Please contact {licenseContact} from {licenseCompany} to obtain a valid license for the Duende software.",
new[] { License.ContactInfo, License.CompanyName });
new object[] { License.ContactInfo, License.CompanyName });
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void RemoveAcrValue(this ValidatedAuthorizeRequest request, string

public static void AddAcrValue(this ValidatedAuthorizeRequest request, string value)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(value);
ArgumentException.ThrowIfNullOrWhiteSpace(value);

request.AuthenticationContextReferenceClasses.Add(value);
var acr_values = request.AuthenticationContextReferenceClasses.ToSpaceSeparatedString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void RemoveCacheEntry(IdentityProvider idp)
var mi = optionsMonitorType.GetMethod("TryRemove");
if (mi != null)
{
mi.Invoke(optionsCache, new[] { idp.Scheme });
mi.Invoke(optionsCache, new object[] { idp.Scheme });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void RemoveCacheEntry(IdentityProvider idp)
if (mi != null)
{
_logger.LogDebug($"Notice: The {provider.OptionsType.Name} object for scheme: {{scheme}} is not being cached. Consider enabling caching for the IIdentityProviderStore with AddIdentityProviderStoreCache<T>() on IdentityServer if you do not want the options to be reinitialized on each request.", idp.Scheme);
mi.Invoke(optionsCache, new[] { idp.Scheme });
mi.Invoke(optionsCache, new object[] { idp.Scheme });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions identity-server/src/IdentityServer/IdentityServerTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public virtual Task<string> IssueJwtAsync(int lifetime, string issuer, IEnumerab
/// <inheritdoc/>
public virtual async Task<string> IssueJwtAsync(int lifetime, string issuer, string tokenType, IEnumerable<Claim> claims)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(issuer);
ArgumentNullException.ThrowIfNullOrWhiteSpace(tokenType);
ArgumentException.ThrowIfNullOrWhiteSpace(issuer);
ArgumentException.ThrowIfNullOrWhiteSpace(tokenType);
ArgumentNullException.ThrowIfNull(claims);

var token = new Token(tokenType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void ValidateLicense()
return;
}

DebugLog.Invoke("The Duende license key details: {@license}", new[] { License });
DebugLog.Invoke("The Duende license key details: {@license}", new object[] { License });

var errors = new List<string>();

Expand All @@ -105,7 +105,7 @@ protected void ValidateLicense()

ErrorLog.Invoke(
"Please contact {licenseContact} from {licenseCompany} to obtain a valid license for the Duende software.",
new[] { License.ContactInfo, License.CompanyName });
new object[] { License.ContactInfo, License.CompanyName });
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task<IEnumerable<Grant>> GetAllGrantsAsync(string subjectId)
{
using var activity = Tracing.ServiceActivitySource.StartActivity("DefaultPersistedGrantService.GetAllGrants");

ArgumentNullException.ThrowIfNullOrWhiteSpace(subjectId);
ArgumentException.ThrowIfNullOrWhiteSpace(subjectId);

var grants = (await _store.GetAllAsync(new PersistedGrantFilter { SubjectId = subjectId }))
.Where(x => x.ConsumedTime == null) // filter consumed grants
Expand Down Expand Up @@ -179,7 +179,7 @@ public Task RemoveAllGrantsAsync(string subjectId, string clientId = null, strin
{
using var activity = Tracing.ServiceActivitySource.StartActivity("DefaultPersistedGrantService.RemoveAllGrants");

ArgumentNullException.ThrowIfNullOrWhiteSpace(subjectId);
ArgumentException.ThrowIfNullOrWhiteSpace(subjectId);

return _store.RemoveAllAsync(new PersistedGrantFilter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,6 @@ public Task<QueryResult<ServerSideSession>> QuerySessionsAsync(SessionQuery filt
Results = results
};

return Task<QueryResult<ServerSideSession>>.FromResult(result);
return Task.FromResult(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ internal ParseScopeContext(string rawScopeValue)
/// <param name="parsedParameter"></param>
public void SetParsedValues(string parsedName, string parsedParameter)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(parsedName);
ArgumentNullException.ThrowIfNullOrWhiteSpace(parsedParameter);
ArgumentException.ThrowIfNullOrWhiteSpace(parsedName);
ArgumentException.ThrowIfNullOrWhiteSpace(parsedParameter);

ParsedName = parsedName;
ParsedParameter = parsedParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ParsedScopeValidationError
/// <param name="error"></param>
public ParsedScopeValidationError(string rawValue, string error)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(rawValue);
ArgumentNullException.ThrowIfNullOrWhiteSpace(error);
ArgumentException.ThrowIfNullOrWhiteSpace(rawValue);
ArgumentException.ThrowIfNullOrWhiteSpace(error);

RawValue = rawValue;
Error = error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public ParsedScopeValue(string rawValue)
/// <param name="parsedParameter"></param>
public ParsedScopeValue(string rawValue, string parsedName, string? parsedParameter)
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(rawValue);
ArgumentNullException.ThrowIfNullOrWhiteSpace(parsedName);
ArgumentException.ThrowIfNullOrWhiteSpace(rawValue);
ArgumentException.ThrowIfNullOrWhiteSpace(parsedName);

RawValue = rawValue;
ParsedName = parsedName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE in the project root for license information.


using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
Expand Down Expand Up @@ -127,10 +128,10 @@ private string GetCode(HttpResponseMessage response)
{
response.StatusCode.Should().Be(HttpStatusCode.Redirect);
var url = response.Headers.Location.ToString();
var idx = url.IndexOf("code=");
var idx = url.IndexOf("code=", StringComparison.Ordinal);
idx.Should().BeGreaterThan(-1);
var code = url.Substring(idx + 5);
idx = code.IndexOf("&");
idx = code.IndexOf("&", StringComparison.Ordinal);
if (idx >= 0)
{
code = code.Substring(0, idx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task RemoveSessionIdCookie_should_remove_cookie()
cookies = _mockHttpContext.HttpContext.Response.Headers.Where(x => x.Key.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase)).Select(x => x.Value);
cookieContainer.SetCookies(new Uri("http://server"), string.Join(',', cookies));

var query = cookieContainer.GetCookies(new Uri("http://server")).Cast<Cookie>().Where(x => x.Name == _options.Authentication.CheckSessionCookieName);
var query = cookieContainer.GetCookies(new Uri("http://server")).Where(x => x.Name == _options.Authentication.CheckSessionCookieName);
query.Count().Should().Be(0);
}

Expand Down
Loading