This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 762
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 #1839 from mvalipour/feature/support-session-store
Add support for cookie session store
- Loading branch information
Showing
6 changed files
with
135 additions
and
1 deletion.
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
38 changes: 38 additions & 0 deletions
38
source/Core/Configuration/AuthenticationSessionStoreWrapper.cs
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,38 @@ | ||
namespace IdentityServer3.Core.Configuration | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Owin.Security; | ||
using Microsoft.Owin.Security.Cookies; | ||
|
||
internal class AuthenticationSessionStoreWrapper : IAuthenticationSessionStore | ||
{ | ||
private readonly IAuthenticationSessionStoreProvider provider; | ||
|
||
public AuthenticationSessionStoreWrapper(IAuthenticationSessionStoreProvider provider) | ||
{ | ||
this.provider = provider; | ||
} | ||
|
||
public Task<string> StoreAsync(AuthenticationTicket ticket) | ||
{ | ||
return this.provider.StoreAsync(new AuthenticationTicketModel(ticket)); | ||
} | ||
|
||
public Task RenewAsync(string key, AuthenticationTicket ticket) | ||
{ | ||
return this.provider.RenewAsync(key, new AuthenticationTicketModel(ticket)); | ||
} | ||
|
||
public async Task<AuthenticationTicket> RetrieveAsync(string key) | ||
{ | ||
var ticket = await this.provider.RetrieveAsync(key); | ||
return ticket == null ? null : ticket.ToAuthenticationTicket(); | ||
} | ||
|
||
public Task RemoveAsync(string key) | ||
{ | ||
return this.provider.RemoveAsync(key); | ||
} | ||
} | ||
} |
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,42 @@ | ||
namespace IdentityServer3.Core.Configuration | ||
{ | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
|
||
using Microsoft.Owin.Security; | ||
|
||
/// <summary> | ||
/// A model class represending an authentication ticket | ||
/// </summary> | ||
public class AuthenticationTicketModel | ||
{ | ||
/// <summary> | ||
/// Instantiates an instance of authentication ticket | ||
/// </summary> | ||
public AuthenticationTicketModel(ClaimsIdentity identity, IDictionary<string, string> properties) | ||
{ | ||
this.Identity = identity; | ||
this.Properties = properties; | ||
} | ||
|
||
internal AuthenticationTicketModel(AuthenticationTicket ticket) | ||
: this(ticket.Identity, ticket.Properties.Dictionary) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// The claims identity of the authentication ticket | ||
/// </summary> | ||
public ClaimsIdentity Identity { get; private set; } | ||
|
||
/// <summary> | ||
/// Authentication ticket properties | ||
/// </summary> | ||
public IDictionary<string, string> Properties { get; private set; } | ||
|
||
internal AuthenticationTicket ToAuthenticationTicket() | ||
{ | ||
return new AuthenticationTicket(this.Identity, new AuthenticationProperties(this.Properties)); | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
source/Core/Configuration/IAuthenticationSessionStoreProvider.cs
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,39 @@ | ||
namespace IdentityServer3.Core.Configuration | ||
{ | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Providers the authentication session stores functions | ||
/// </summary> | ||
public interface IAuthenticationSessionStoreProvider | ||
{ | ||
/// <summary> | ||
/// Provides the remove functionality of session store | ||
/// </summary> | ||
/// <param name="key">Session key</param> | ||
/// <returns>Async task</returns> | ||
Task RemoveAsync(string key); | ||
|
||
/// <summary> | ||
/// Provides the renew functionality of session store | ||
/// </summary> | ||
/// <param name="key">Session key</param> | ||
/// <param name="identity">Authentication ticket</param> | ||
/// <returns>Async task</returns> | ||
Task RenewAsync(string key, AuthenticationTicketModel identity); | ||
|
||
/// <summary> | ||
/// Provides the retrieve functionality of session store | ||
/// </summary> | ||
/// <param name="key">Session key</param> | ||
/// <returns>Async task with authentication ticket result</returns> | ||
Task<AuthenticationTicketModel> RetrieveAsync(string key); | ||
|
||
/// <summary> | ||
/// Provides the store functionality of session store | ||
/// </summary> | ||
/// <param name="ticket">Authentication ticket</param> | ||
/// <returns>Async task with session key</returns> | ||
Task<string> StoreAsync(AuthenticationTicketModel ticket); | ||
} | ||
} |
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