Skip to content

Commit db85ded

Browse files
author
Daniele Giallonardo
committed
Fix load properties su SignOut
1 parent 7b06bbc commit db85ded

2 files changed

Lines changed: 18 additions & 21 deletions

File tree

CIE.AspNetCore.Authentication/CIE.AspNetCore.Authentication/CIE.AspNetCore.Authentication.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<PackageProjectUrl>https://github.com/italia/cie-aspnetcore</PackageProjectUrl>
1313
<PackageIcon>cie-nuget.png</PackageIcon>
1414
<PackageLicenseExpression>MIT</PackageLicenseExpression>
15-
<PackageVersion>2.0.3</PackageVersion>
16-
<Version>2.0.3</Version>
17-
<AssemblyVersion>2.0.3</AssemblyVersion>
18-
<FileVersion>2.0.3</FileVersion>
19-
<InformationalVersion>2.0.3</InformationalVersion>
15+
<PackageVersion>2.0.4</PackageVersion>
16+
<Version>2.0.4</Version>
17+
<AssemblyVersion>2.0.4</AssemblyVersion>
18+
<FileVersion>2.0.4</FileVersion>
19+
<InformationalVersion>2.0.4</InformationalVersion>
2020
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
2121
<PackageReadmeFile>README.md</PackageReadmeFile>
2222
<RepositoryUrl>https://github.com/italia/cie-aspnetcore</RepositoryUrl>

CIE.AspNetCore.Authentication/CIE.AspNetCore.Authentication/CieHandler.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,11 @@ public async virtual Task SignOutAsync(AuthenticationProperties properties)
195195

196196
string authenticationRequestId = Guid.NewGuid().ToString();
197197

198-
var requestProperties = new AuthenticationProperties();
199-
requestProperties.Load(Request, Options.StateDataFormat);
198+
properties.Load(Request, Options.StateDataFormat);
200199

201200
// Extract the user state from properties and reset.
202-
var subjectNameId = requestProperties.GetSubjectNameId();
203-
var sessionIndex = requestProperties.GetSessionIndex();
201+
var subjectNameId = properties.GetSubjectNameId();
202+
var sessionIndex = properties.GetSessionIndex();
204203

205204
var idp = Options.IdentityProvider;
206205

@@ -238,7 +237,7 @@ await _requestGenerator.HandleRequest(message,
238237

239238
protected virtual async Task<bool> HandleRemoteSignOutAsync()
240239
{
241-
var (id, message, serializedResponse) = await ExtractInfoFromSignOutResponse();
240+
var (message, serializedResponse) = await ExtractInfoFromSignOutResponse();
242241

243242
AuthenticationProperties requestProperties = new AuthenticationProperties();
244243
requestProperties.Load(Request, Options.StateDataFormat);
@@ -433,7 +432,7 @@ await _logHandler.LogRedirectResponse(new RedirectResponse()
433432
return (null, null, null);
434433
}
435434

436-
private async Task<(string Id, LogoutResponseType Message, string serializedResponse)> ExtractInfoFromSignOutResponse()
435+
private async Task<(LogoutResponseType Message, string serializedResponse)> ExtractInfoFromSignOutResponse()
437436
{
438437
if (HttpMethods.IsPost(Request.Method)
439438
&& !string.IsNullOrEmpty(Request.ContentType)
@@ -455,9 +454,7 @@ await _logHandler.LogPostResponse(new PostResponse()
455454
Cookies = Request.Cookies.ToDictionary(t => t.Key, t => t.Value)
456455
});
457456

458-
return (
459-
form["RelayState"].ToString(),
460-
SamlHandler.GetLogoutResponse(serializedResponse),
457+
return (SamlHandler.GetLogoutResponse(serializedResponse),
461458
serializedResponse
462459
);
463460
}
@@ -477,13 +474,11 @@ await _logHandler.LogRedirectResponse(new RedirectResponse()
477474
Cookies = Request.Cookies.ToDictionary(t => t.Key, t => t.Value)
478475
});
479476

480-
return (
481-
Request.Query["RelayState"].FirstOrDefault(),
482-
SamlHandler.GetLogoutResponse(serializedResponse),
477+
return (SamlHandler.GetLogoutResponse(serializedResponse),
483478
serializedResponse
484479
);
485480
}
486-
return (null, null, null);
481+
return (null, null);
487482
}
488483

489484
private static string DecompressString(string value)
@@ -735,6 +730,7 @@ public static void Save(this AuthenticationProperties properties, HttpResponse r
735730

736731
public static void Load(this AuthenticationProperties properties, HttpRequest request, ISecureDataFormat<AuthenticationProperties> encryptor)
737732
{
733+
BusinessValidation.ValidationCondition(() => !request.Cookies.ContainsKey(CieDefaults.CookieName), ErrorLocalization.CiePropertiesNotFound);
738734
var cookie = request.Cookies[CieDefaults.CookieName];
739735
BusinessValidation.ValidationNotNull(cookie, ErrorLocalization.CiePropertiesNotFound);
740736
AuthenticationProperties cookieProperties = encryptor.Unprotect(cookie);
@@ -743,15 +739,16 @@ public static void Load(this AuthenticationProperties properties, HttpRequest re
743739
properties.ExpiresUtc = cookieProperties.ExpiresUtc;
744740
properties.IsPersistent = cookieProperties.IsPersistent;
745741
properties.IssuedUtc = cookieProperties.IssuedUtc;
746-
foreach (var item in cookieProperties.Items)
742+
foreach (var item in cookieProperties.Items.Where(i => !properties.Items.ContainsKey(i.Key)))
747743
{
748744
properties.Items.Add(item);
749745
}
750-
foreach (var item in cookieProperties.Parameters)
746+
foreach (var item in cookieProperties.Parameters.Where(i => !properties.Parameters.ContainsKey(i.Key)))
751747
{
752748
properties.Parameters.Add(item);
753749
}
754-
properties.RedirectUri = cookieProperties.RedirectUri;
750+
if (string.IsNullOrWhiteSpace(properties.RedirectUri))
751+
properties.RedirectUri = cookieProperties.RedirectUri;
755752
}
756753
}
757754
}

0 commit comments

Comments
 (0)