-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #964 from ITfoxtec/test
Test
- Loading branch information
Showing
18 changed files
with
145 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using FoxIDs.Infrastructure; | ||
using FoxIDs.Models; | ||
using FoxIDs.Models.Config; | ||
using FoxIDs.Models.Sequences; | ||
using FoxIDs.Repository; | ||
using Microsoft.AspNetCore.Http; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace FoxIDs.Logic | ||
{ | ||
public class StateUpPartyLogic : SessionBaseLogic | ||
{ | ||
private readonly TelemetryScopedLogger logger; | ||
private readonly UpPartyCookieRepository<StateUpPartyCookie> stateCookieRepository; | ||
|
||
public StateUpPartyLogic(FoxIDsSettings settings, TelemetryScopedLogger logger, UpPartyCookieRepository<StateUpPartyCookie> stateCookieRepository, IHttpContextAccessor httpContextAccessor) : base(settings, httpContextAccessor) | ||
{ | ||
this.logger = logger; | ||
this.stateCookieRepository = stateCookieRepository; | ||
} | ||
|
||
public async Task CreateOrUpdateStateCookieAsync<T>(T upParty, string state) where T : UpParty | ||
{ | ||
logger.ScopeTrace(() => $"Create or update authentication method state cookie, Route '{RouteBinding.Route}'."); | ||
|
||
Action<StateUpPartyCookie> updateAction = (stateCookie) => | ||
{ | ||
stateCookie.State = state; | ||
}; | ||
|
||
var stateCookie = await stateCookieRepository.GetAsync(upParty); | ||
if (stateCookie != null) | ||
{ | ||
updateAction(stateCookie); | ||
stateCookie.LastUpdated = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); | ||
} | ||
else | ||
{ | ||
stateCookie = new StateUpPartyCookie(); | ||
updateAction(stateCookie); | ||
stateCookie.LastUpdated = stateCookie.CreateTime; | ||
} | ||
|
||
await stateCookieRepository.SaveAsync(upParty, stateCookie, null); | ||
} | ||
|
||
public async Task<string> GetAndDeleteStateCookieAsync<T>(T upParty) where T : UpParty | ||
{ | ||
logger.ScopeTrace(() => $"Get and delete authentication method state cookie, Route '{RouteBinding.Route}'."); | ||
|
||
var stateCookie = await stateCookieRepository.GetAsync(upParty); | ||
if(stateCookie != null) | ||
{ | ||
await stateCookieRepository.DeleteAsync(upParty); | ||
} | ||
return stateCookie.State; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using FoxIDs.Models.Session; | ||
using Microsoft.AspNetCore.Http; | ||
using Newtonsoft.Json; | ||
|
||
namespace FoxIDs.Models.Sequences | ||
{ | ||
public class StateUpPartyCookie : CookieMessage | ||
{ | ||
[JsonIgnore] | ||
public override SameSiteMode SameSite => SameSiteMode.None; | ||
|
||
[JsonProperty(PropertyName = "s")] | ||
public string State { get; set; } | ||
} | ||
} |